unleash-server 5.3.0 → 5.3.1
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.
- package/dist/lib/services/client-metrics/metrics-service-v2.d.ts +2 -0
- package/dist/lib/services/client-metrics/metrics-service-v2.js +27 -17
- package/dist/lib/services/client-metrics/metrics-service-v2.js.map +1 -1
- package/dist/lib/services/client-metrics/metrics-service-v2.test.d.ts +1 -0
- package/dist/lib/services/client-metrics/metrics-service-v2.test.js +96 -0
- package/dist/lib/services/client-metrics/metrics-service-v2.test.js.map +1 -0
- package/dist/lib/types/experimental.d.ts +1 -1
- package/dist/lib/types/experimental.js +1 -0
- package/dist/lib/types/experimental.js.map +1 -1
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{AdvancedPlayground-4c9d02ea.js → AdvancedPlayground-48dddbf4.js} +1 -1
- package/frontend/build/static/{CreateProject-16b35d57.js → CreateProject-c1b0f704.js} +1 -1
- package/frontend/build/static/{Error-50364f10.js → Error-e6f7c2ee.js} +1 -1
- package/frontend/build/static/FeatureArchiveDialog-9ad60db1.js +10 -0
- package/frontend/build/static/{FeatureMetricsChart-839cdf1e.js → FeatureMetricsChart-81da0ce4.js} +1 -1
- package/frontend/build/static/{FeatureViewLazyExport-47bb7f13.js → FeatureViewLazyExport-58a3e977.js} +2 -2
- package/frontend/build/static/{LazyAdminExport-8ef0ca21.js → LazyAdminExport-c98b11d7.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-49541c75.js → LazyProjectExport-14db2e37.js} +1 -1
- package/frontend/build/static/{NetworkOverview-711050f3.js → NetworkOverview-cd06e59f.js} +2 -2
- package/frontend/build/static/{NetworkTraffic-e587c2c7.js → NetworkTraffic-ba933617.js} +1 -1
- package/frontend/build/static/{RoleCell-9a62b4ed.js → RoleCell-c534790e.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-4098c8ef.js → StrategyItemContainer-88c18285.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-d57aaddd.js → chartjs-adapter-date-fns.esm-799be047.js} +1 -1
- package/frontend/build/static/{flowchart-elk-definition-170a3958-4dece62b.js → flowchart-elk-definition-170a3958-543f0844.js} +1 -1
- package/frontend/build/static/{index-9c528324.js → index-1c4c68c3.js} +2 -2
- package/frontend/build/static/{index-9bb67f88.js → index-88f1c682.js} +1 -1
- package/frontend/build/static/{index-1c8194e0.js → index-aa638b65.js} +1 -1
- package/frontend/build/static/{is_dark-ba77f0b9.js → is_dark-735e3a95.js} +1 -1
- package/frontend/build/static/{mindmap-definition-44684416-a4071c9f.js → mindmap-definition-44684416-ac92f950.js} +1 -1
- package/frontend/build/static/{timeline-definition-8e5a9bc6-c996bf40.js → timeline-definition-8e5a9bc6-6c09f608.js} +1 -1
- package/frontend/build/static/{unknownify-db48ebae.js → unknownify-0b176a78.js} +1 -1
- package/package.json +1 -1
- package/frontend/build/static/FeatureArchiveDialog-fda1aa0c.js +0 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{c as Lt,j as t,s as d,aD as A,aE as V,aF as pn,d as r,aG as gn,C as E,aH as Z,aI as pe,aJ as Y,aK as ye,aL as hn,aM as ot,r as f,aN as Te,aO as Be,aP as st,aQ as fn,aR as mn,aS as yn,aT as Sn,f as U,aU as Me,aV as fe,h as N,T as q,aW as we,aX as xe,aY as bn,aZ as se,a_ as ge,a$ as X,t as rt,b0 as Cn,b1 as vn,b2 as Ee,M as he,b3 as $e,b4 as jt,b5 as Se,b6 as ae,au as re,E as ie,b7 as Vt,b8 as Tn,b9 as wn,ba as xn,bb as En,bc as et,bd as An,be as Rn,y as _,B as J,bf as In,bg as Fn,bh as Dn,bi as kn,bj as $n,bk as Pn,bl as Bn,bm as Mn,bn as On,G as _n,b as zt,aa as Oe,x as be,bo as it,i as me,N as ct,bp as Wt,ag as _e,V as Ln,bq as lt,br as ue,bs as oe,bt as jn,$ as Vn,bu as zn,bv as ee,bw as Wn,bx as Nn,R as qn,by as Hn,bz as Un,bA as Gn,bB as Yn,bC as Nt,bD as Kn,bE as Jn,bF as qt,bG as Qn,bH as Ht,bI as Xn,bJ as Zn,bK as dt,bL as ea,bM as ta,bN as Le,bO as na,L as Ut,D as Ce,bP as aa,bQ as oa,bR as sa,bS as Gt,bT as Yt,bU as ne,bV as tt,bW as ra,bX as Kt,bY as ia,X as Jt,g as ca,bZ as la,b_ as ze,b$ as gt,as as da,ax as ua,c0 as de,c1 as pa,c2 as ht,c3 as ga,c4 as ha,m as fa,aq as ut,ar as ma,al as ft,c5 as ya,c6 as Sa,c7 as ba,c8 as mt,a9 as Qt,c9 as Ca,a1 as We,ac as va,a3 as Ta,a4 as wa,a5 as xa,a6 as Ea,a7 as Aa,a8 as Ra,ca as Ia,cb as yt,cc as Fa,cd as Xt,ce as Da,q as ka,cf as St,cg as $a,ch as Pa,ci as Ba,cj as Ma,ck as Oa,cl as _a,ai as La,cm as ja,cn as Va,co as za,cp as Wa,cq as Na,cr as qa}from"./index-9c528324.js";import{C as Zt,f as en,E as Ha,F as Ua,V as Ga,a as Ya,u as Ka,b as Ja,T as Qa,c as Xa,d as Za,W as eo,e as to,g as no}from"./FeatureArchiveDialog-fda1aa0c.js";import{S as ao}from"./StrategyItemContainer-4098c8ef.js";const oo=Lt(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"),so=Lt(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=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),io=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n);return a.name?t(ro,{children:t(pn,{title:"Event log",feature:n,displayInline:!0})}):null},co=d("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"}})),lo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),uo=d("div")({display:"flex",alignItems:"center"}),po=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),go=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),bt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Ct=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),ho=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n),{project:s,description:o,type:i}=a,c=hn(i);return t(co,{children:r(lo,{children:[r(uo,{"data-loading":!0,children:[t(c,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",r(po,{children:[gn(i||"")," toggle"]})]}),r(go,{children:[r(bt,{"data-loading":!0,children:["Project: ",s]}),t(E,{condition:!!o,show:r(bt,{"data-loading":!0,children:[t("div",{children:"Description:"}),r(Ct,{children:[t("p",{children:o}),t(Z,{projectId:e,permission:pe,component:Y,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:r(Ct,{children:["No description."," ",t(Z,{projectId:e,permission:pe,component:Y,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},vt={lastHourUsage:[],seenApplications:[]},fo=(e,n,a={})=>{const s=async()=>{const g=Te(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Be("feature metrics"));return h.ok?h.json():vt},o=`${e}_${n}_metrics`,{data:i,error:c}=ot(o,s,{...a}),[l,p]=f.useState(!c&&!i),u=()=>{st(o)};return f.useEffect(()=>{p(!c&&!i)},[i,c]),{metrics:i||vt,error:c,loading:l,refetch:u,FEATURE_METRICS_CACHE_KEY:o}},mo=e=>({yes:0,no:0,environment:e,timestamp:""}),yo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||mo(a.name)),So=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s)),bo=fn(ot,So),tn=(e,n)=>{const{refetchFeature:a}=V(e,n),s=mn(e,n),{data:o,error:i,mutate:c}=bo(["useFeatureImmutable",s],()=>yn(s)),l=f.useCallback(async()=>{await c(),await a()},[c,a]);return{feature:(o==null?void 0:o.body)||Sn,refetchFeature:l,loading:!i&&!o,status:o==null?void 0:o.status,error:i}},nn=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=U(),{addChange:i}=Me(),{refetch:c}=fe(e),[l,p]=f.useState({isOpen:!1}),u=f.useCallback((C,R,y)=>{p({featureName:n,environment:C,fromEnvironment:y,strategy:R,isOpen:!0})},[]),g=f.useCallback((C,R,y)=>{p({featureName:n,environment:C,fromEnvironment:y,strategies:R,isOpen:!0})},[]),h=f.useCallback(()=>{p({isOpen:!1})},[]),S=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),c(),p({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(C){o(N(C)),p({isOpen:!1})}},[i]),b=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(C=>i(e,l.environment,{feature:l.featureName,action:a,payload:C}))),c(),p({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(C){o(N(C)),p({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategiesConfirm:b,changeRequestDialogDetails:l}},Co=({payload:e,fromEnvironment:n,environment:a})=>r(q,{children:[r("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),vo=({environmentId:e,environments:n,strategy:a})=>{const s=A("projectId"),o=A("featureId"),[i,c]=f.useState(null),l=!!i,{addStrategyToFeature:p}=xe(),{setToastData:u,setToastApiError:g}=U(),{refetchFeature:h}=V(s,o),{refetchFeature:S}=tn(s,o),b=()=>{c(null)},C=bn(s),{isChangeRequestConfigured:R}=se(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:m,onChangeRequestAddStrategy:T,onChangeRequestAddStrategyConfirm:F}=nn(s,o,"addStrategy"),$=async k=>{const{id:P,...B}={...a,targetEnvironment:k};if(R(k)){await T(k,{id:P,...B},e);return}try{await p(s,o,k,a),h(),S(),u({title:"Strategy created",text:`Successfully copied a strategy to ${k}`,type:"success"})}catch(G){g(N(G))}b()},j=n.some(k=>C(ge,k));return r("div",{children:[t(Zt,{isOpen:y.isOpen,onClose:m,environment:y==null?void 0:y.environment,onConfirm:F,messageComponent:t(Co,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(X,{title:`Copy to another environment${j?"":" (Access denied)"}`,children:t("div",{children:t(rt,{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:k=>{c(k.currentTarget)},"data-testid":Cn,disabled:!j,children:t(vn,{})})})}),t(Ee,{id:"basic-menu",anchorEl:i,open:l,onClose:b,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(k=>{const P=C(ge,k);return t(X,{title:P?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(he,{onClick:()=>$(k),disabled:!P,children:[t(E,{condition:!P,show:t($e,{children:t(jt,{fontSize:"small"})})}),r(Se,{children:["Copy to ",k]})]})})},k)})})]})},an=()=>t(ie,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),To=({onRemove:e,onClose:n,isOpen:a})=>t(ae,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(an,{})}),wo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),xo=({onRemove:e,onClose:n,isOpen:a})=>r(ae,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(an,{}),t(wo,{children:t(q,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(q,{fontWeight:"bold",children:"Remove strategy"})]}),Eo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=xe(),{setToastData:i,setToastApiError:c}=U(),l=re(),{refetchFeature:p}=V(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),p(),l(Vt(e,n))}catch(h){c(N(h))}}},Ao=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=Me(),{refetch:i}=fe(e),{setToastData:c,setToastApiError:l}=U();return async u=>{try{u.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(N(g))}}},Ro=({projectId:e,featureId:n,environmentId:a,strategyId:s,text:o,isOpen:i,onClose:c})=>{const{isChangeRequestConfigured:l}=se(e),p=Eo({featureId:n,projectId:e,strategyId:s,environmentId:a}),u=Ao({featureId:n,projectId:e,strategyId:s,environmentId:a});return l(a)?t(xo,{isOpen:i,onClose:()=>c(),onRemove:async g=>{await u(g),c()}}):t(To,{isOpen:i,onClose:()=>c(),onRemove:p})},Io=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=V(e,a),{setStrategyDisabledState:i}=xe(),{setToastData:c,setToastApiError:l}=U(),p=u=>async()=>{try{await i(e,a,n,s.id,!u),c({title:`Strategy ${u?"enabled":"disabled"}`,type:"success"}),o()}catch(g){l(N(g))}};return{onDisable:p(!1),onEnable:p(!0)}},Fo=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=Me(),{refetch:i}=fe(e),{setToastData:c,setToastApiError:l}=U(),p=u=>async()=>{try{await o(e,n,{action:"updateStrategy",feature:a,payload:{...s,disabled:!u}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(N(g))}};return{onSuggestDisable:p(!1),onSuggestEnable:p(!0)}},Do=({isOpen:e,onClose:n,...a})=>{var b;const{projectId:s,environmentId:o}=a,{isChangeRequestConfigured:i}=se(s),c=i(o),{onSuggestEnable:l,onSuggestDisable:p}=Fo({...a}),{onEnable:u,onDisable:g}=Io({...a}),h=!!((b=a.strategy)!=null&&b.disabled);return t(ae,{title:c?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:c?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:C=>{C.preventDefault(),c?h?l():p():h?u():g(),n()},onClose:()=>n(),children:t(E,{condition:c,show:t(Tn,{environment:o}),elseShow:r(ie,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var pt={},ko=xn;Object.defineProperty(pt,"__esModule",{value:!0});var on=pt.default=void 0,$o=ko(wn()),Po=En,Bo=(0,$o.default)((0,Po.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");on=pt.default=Bo;const Mo=({projectId:e,strategy:n,featureId:a,environmentId:s})=>{const[o,i]=f.useState(null),[c,l]=f.useState(!1),[p,u]=f.useState(!1),g=!!o,h=R=>{i(R.currentTarget)},S=R=>{i(null),R.stopPropagation()},b=et(An,e,s),C=et(Rn,e,s);return r(_,{children:[t(J,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(X,{title:"More actions",children:t(rt,{onClick:h,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":In,children:t(Fn,{sx:{width:32,height:32}})})})}),r(Ee,{anchorEl:o,id:"actions-menu",open:g,onClose:S,onClick:S,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Dn,children:[t(X,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:r(he,{disabled:!b,onClick:()=>l(!0),children:[t($e,{children:n.disabled?t(kn,{}):t($n,{})}),t(Se,{children:n.disabled?"Enable":"Disable"})]})}),t(X,{title:"Remove strategy",arrow:!0,placement:"left",children:r(he,{disabled:!C,onClick:()=>u(!0),"data-testid":Pn,children:[t($e,{children:t(on,{})}),t(Se,{children:"Remove"})]})})]}),t(Do,{isOpen:c,onClose:()=>l(!1),projectId:e,featureId:a,environmentId:s,strategy:n}),t(Ro,{isOpen:p,onClose:()=>u(!1),projectId:e,featureId:a,environmentId:s,strategyId:n.id})]})},Oo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:c})=>{const l=A("projectId"),p=A("featureId"),u=Bn(l,p,e,n.id);return t(ao,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:r(_,{children:[c,t(E,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t(vo,{environmentId:e,environments:o,strategy:n})}),t(Z,{permission:Mn,environmentId:e,projectId:l,component:Y,to:u,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(ye,{})}),t(Mo,{projectId:l,featureId:p,environmentId:e,strategy:n})]}),children:t(On,{strategy:n})})},_o=(e,n,a,s)=>{const{data:o}=fe(e),i=o==null?void 0:o.find(p=>p.environment===a),c=i==null?void 0:i.features.find(p=>p.name===n);return c==null?void 0:c.changes.find(p=>p.action==="updateStrategy"||p.action==="deleteStrategy"?p.payload.id===s:!1)},Lo=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:c,onDragEnd:l})=>{const p=A("projectId"),u=A("featureId"),g=f.useRef(null),h=_o(p,u,a,e.id);return r(J,{ref:g,onDragOver:c(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(_n,{text:"OR"})}),t(Oo,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(g,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(jo,{change:h})})]},e.id)},jo=({change:e})=>{const n=zt();return Oe(n.breakpoints.down("sm"))?null:r(J,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(be,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(be,{color:"error",children:"Deleted in draft"})})]})},Vo=({environmentId:e,environments:n,onClick:a})=>{const s=A("projectId"),[o,i]=f.useState(null),c=!!o,{hasAccess:l}=f.useContext(it),p=n.some(u=>l(ge,s,u));return r("div",{children:[t(X,{title:p?"":"(Access denied)",children:t("div",{children:t(me,{id:`copy-all-strategies-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:u=>{i(u.currentTarget)},disabled:!p,variant:"outlined",children:"Copy from another environment"})})}),t(Ee,{id:"basic-menu",anchorEl:o,open:c,onClose:()=>{i(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=l(ge,s,u);return t(X,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(he,{onClick:()=>a(u),disabled:!g,children:[t(E,{condition:!g,show:t($e,{children:t(jt,{fontSize:"small"})})}),r(Se,{children:["Copy from ",u]})]})})},u)})})]})},zo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Wo=({payload:e,fromEnvironment:n,environment:a})=>r(zo,{children:[t(q,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>r(q,{children:[r("strong",{children:[we((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),r(q,{children:["from ",n," to ",a]})]}),No=d("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}})),qo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Ho=d(ct)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Uo=d(Y)(({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}})),Ne=({projectId:e,featureId:n,environmentId:a,strategy:s,defaultStrategy:o})=>{const i=Wt(s.name),c=we(s.name),{trackEvent:l}=_e(),p=en(e,n,a,s.name,o);return r(Uo,{to:p,onClick:()=>{l("strategy-add",{props:{buttonTitle:s.displayName||c}})},children:[t(No,{children:t(i,{})}),r("div",{children:[t(Ho,{text:s.displayName||c,maxWidth:"200",maxLength:25}),t(qo,{children:s.description})]})]})},qe=d(q)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),Go=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=Ln(),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(lt,{dense:!0,children:[r(_,{children:[r(qe,{color:"textSecondary",children:[a," environment default strategy"]}),t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:c,defaultStrategy:!0})},c.name)]}),t(qe,{color:"textSecondary",children:"Predefined strategy types"}),o.map(l=>t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name)),t(E,{condition:i.length>0,show:r(_,{children:[t(qe,{color:"textSecondary",children:"Custom strategies"}),i.map(l=>t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))]})})]})},Yo=d("div")({flexShrink:0}),Ko=d(oe)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),nt=({label:e,projectId:n,featureId:a,environmentId:s,variant:o,size:i,matchWidth:c})=>{const[l,p]=f.useState(),u=re(),{trackEvent:g}=_e(),h=!!l,S=h?"FeatureStrategyMenuPopover":void 0,b=()=>{p(void 0)},C=m=>{g("strategy-add",{props:{buttonTitle:e}}),u(y)},R=m=>{p(m.currentTarget)},y=en(n,a,s,"flexibleRollout",!0);return r(Yo,{onClick:m=>m.stopPropagation(),children:[t(oe,{permission:ge,projectId:n,environmentId:s,onClick:C,"aria-labelledby":S,variant:o,size:i,sx:{minWidth:c?"282px":"auto"},children:e}),t(Ko,{permission:ge,projectId:n,environmentId:s,onClick:R,"aria-labelledby":S,variant:"outlined",size:i,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(jn,{sx:m=>({margin:m.spacing(.25,0)})})}),t(Vn,{id:S,open:h,anchorEl:l,onClose:b,onClick:b,PaperProps:{sx:m=>({paddingBottom:m.spacing(1)})},children:t(Go,{projectId:n,featureId:a,environmentId:s})})]})},Jo=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Qo=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Xo=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),Zo=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=xe(),{setToastData:o,setToastApiError:i}=U(),{refetchFeature:c}=V(e,n),{refetchFeature:l}=tn(e,n),{feature:p}=V(e,n),u=p==null?void 0:p.environments.filter(T=>T.name!==a&&T.strategies&&T.strategies.length>0),{isChangeRequestConfigured:g}=se(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:S,onChangeRequestAddStrategiesConfirm:b,onChangeRequestAddStrategyClose:C}=nn(e,n,"addStrategy"),R=(T=!1)=>{c(),l(),o({title:T?"Strategies created":"Strategy created",text:T?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async T=>{var $;const F=(($=u==null?void 0:u.find(j=>j.name===T))==null?void 0:$.strategies)||[];if(g(a)){await S(a,F,T);return}try{await Promise.all(F.map(j=>{const{id:k,...P}={...j,environment:a};return s(e,n,a,P)})),R(!0)}catch(j){i(N(j))}},m=u&&u.length>0;return r(_,{children:[t(Zt,{isOpen:h.isOpen,onClose:C,environment:h==null?void 0:h.environment,onConfirm:b,messageComponent:t(Wo,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),r(Jo,{children:[t(Qo,{children:"You have not defined any strategies yet."}),r(Xo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(Y,{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(nt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:m}),t(E,{condition:m,show:t(Vo,{environmentId:a,environments:u.map(T=>T.name),onClick:y})})]})]})]})},es=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ts=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ns=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=A("projectId"),o=A("featureId"),{setStrategiesSortOrder:i}=xe(),{setToastData:c,setToastApiError:l}=U(),{refetchFeature:p}=V(s,o),[u,g]=f.useState((e==null?void 0:e.strategies)||[]),[h,S]=f.useState(null);if(f.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const b=async m=>{try{await i(s,o,e.name,m),p(),c({title:"Order of strategies updated",type:"success"})}catch(T){l(N(T))}},C=(m,T)=>F=>{var $;S({id:u[T].id,index:T,height:(($=m.current)==null?void 0:$.offsetHeight)||0}),m!=null&&m.current&&(F.dataTransfer.effectAllowed="move",F.dataTransfer.setData("text/html",m.current.outerHTML),F.dataTransfer.setDragImage(m.current,20,20))},R=m=>(T,F)=>$=>{if(h===null||T.current===null||h.index===F||m===h.id)return;const{top:j,bottom:k}=T.current.getBoundingClientRect(),P=$.clientY-j<h.height,B=k-$.clientY<h.height,G=h.index>F;if(P&&G||B&&!G){const K=[...u],te=K.splice(h.index,1)[0];K.splice(F,0,te),g(K),S({...h,index:F})}},y=()=>{S(null),b(u.map((m,T)=>({id:m.id,sortOrder:T})))};return t(es,{children:r(ts,{children:[t(E,{condition:u.length>0&&n,show:()=>t(ie,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:u.length>0,show:t(_,{children:u.map((m,T)=>t(Lo,{strategy:m,index:T,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===m.id,onDragStartRef:C,onDragOver:R(m.id),onDragEnd:y},m.id))}),elseShow:t(Zo,{projectId:s,featureId:o,environmentId:e.name})})]})})},sn=(e,n)=>e===0?0:Math.round(n/e*100);var je={},Ve={};Object.defineProperty(Ve,"__esModule",{value:!0});Ve.defaultOptions=void 0;Ve.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var Q={};Object.defineProperty(Q,"__esModule",{value:!0});Q.getLocales=Q.getFractionDigits=Q.roundTo=Q.parseValue=void 0;function as(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}Q.parseValue=as;function os(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))}Q.roundTo=os;function ss(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}Q.getFractionDigits=ss;function rs(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}Q.getLocales=rs;Object.defineProperty(je,"__esModule",{value:!0});je.millify=void 0;const Tt=Ve,Fe=Q,wt=1e3;function*xt(e){let n=wt;for(;;){const a=e/n;if(a<1)return;yield a,n*=wt}}function rn(e,n){var a,s;const o=n?{...Tt.defaultOptions,...n}:Tt.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let i;try{i=Fe.parseValue(e)}catch(C){return C instanceof Error&&console.warn(`WARN: ${C.message} (millify)`),String(e)}const c=i<0?"-":"";i=Math.abs(i);let l=0;for(const C of xt(i))i=C,l+=1;if(l>=o.units.length)return e.toString();let u=Fe.roundTo(i,o.precision);for(const C of xt(u))u=C,l+=1;const g=(a=o.units[l])!==null&&a!==void 0?a:"",h=o.lowercase?g.toLowerCase():g,S=o.space?" ":"",b=u.toLocaleString((s=o.locales)!==null&&s!==void 0?s:Fe.getLocales(),{minimumFractionDigits:Fe.getFractionDigits(u)});return`${c}${b}${S}${h}`}je.millify=rn;var is=je.default=rn;const Pe=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=is(e,{precision:a}),o=!0);const i=t("span",{"data-testid":zn,children:s});return t(E,{condition:o,show:t(X,{title:e.toLocaleString(),arrow:!0,children:i}),elseShow:i})},He=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Ue=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),Ge=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),Ye=d("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})),cn=({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(ee,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Exposure"}),t(Ge,{children:t(Pe,{value:e})}),r(Ye,{children:["Total exposure of the feature in the environment"," ",i,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Exposure %"}),r(Ge,{children:[sn(e+n,e),"%"]}),r(Ye,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Requests"}),t(Ge,{children:t(Pe,{value:e+n})}),r(Ye,{children:["Total requests for the feature in the environment"," ",i,"."]})]})})]})},cs=d("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}})),ls=d("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})),ds=({children:e})=>t(cs,{children:t(ls,{children:e})}),us=({environmentMetric:e})=>e?r(_,{children:[t(ds,{children:"Feature toggle exposure"}),t("div",{children:t(cn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Et=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),At=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Rt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),It=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),ps=d(Wn)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),gs=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),hs=({environmentMetric:e,disabled:n=!1})=>{const a=Nn();if(!e)return null;const s=e.yes+e.no,o=sn(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?r(Et,{children:[r(At,{children:[r(Rt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),r(It,{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(Et,{children:[r(At,{children:[r(Rt,{children:[o,"%"]}),r(It,{children:["The feature has been requested"," ",r("b",{children:[t(Pe,{value:s})," times"]})," ","and exposed"," ",r("b",{children:[t(Pe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(gs,{"data-loading":!0,children:t(qn,{percentage:o,size:"3rem"})})]})},Ke=({strategy:e})=>{const n=Wt(e.name);return t(X,{title:we(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t(fs,{children:t(n,{})})})},fs=d("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)}})),Ft=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Je=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),ms=d("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),De=5,ys=({strategies:e})=>e!=null&&e.length?e.length>De+1?r(Ft,{"aria-label":"Feature strategies",children:[e.slice(0,De).map(n=>t(Je,{children:t(Ke,{strategy:n})},n.id)),r(Hn,{tooltip:e.slice(De).map(n=>t(Je,{children:r(ms,{children:[t(Ke,{strategy:n})," ",we(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-De,")"]})]}):t(Ft,{"aria-label":"Feature strategies",children:e.map(n=>t(Je,{children:t(Ke,{strategy:n})},n.id))}):null,Ss=d("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})),bs=d(Un)({boxShadow:"none",background:"none"}),Cs=d(Gn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),vs=d(Yn,{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)}})),Ts=d(ns)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ws=d("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})),xs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Es=d(Ha)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),As=d(ct)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Rs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),Is=({env:e})=>{var u;const n=A("projectId"),a=A("featureId"),{metrics:s}=fo(n,a),{feature:o}=V(n,a),{value:i}=Nt(),l=yo(o==null?void 0:o.environments,s).find(g=>g.environment===e.name),p=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!new Set(i.hiddenEnvironments).has(e.name),show:t(Ss,{enabled:e.enabled,children:r(bs,{"data-testid":`${Kn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[r(Cs,{expandIcon:t(Jn,{titleAccess:"Toggle"}),children:[r(ws,{"data-loading":!0,enabled:e.enabled,children:[r(xs,{children:[t(Es,{enabled:e.enabled}),t("div",{children:t(As,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(be,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),r(Rs,{children:[t(nt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"}),t(ys,{strategies:p==null?void 0:p.strategies})]})]}),t(hs,{environmentMetric:l,disabled:!e.enabled})]}),r(vs,{enabled:e.enabled,children:[t(Ts,{featureEnvironment:p,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((u=p==null?void 0:p.strategies)==null?void 0:u.length)||0)>0,show:r(_,{children:[t(J,{sx:{display:"flex",justifyContent:"center",py:1},children:t(nt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(us,{environmentMetric:l})]})})]})]})})})},Fs=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n);if(!a)return null;const{environments:s}=a;return t(_,{children:s==null?void 0:s.map(o=>t(Is,{env:o},o.name))})},Ds=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),ks=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),$s=({feature:e,header:n})=>{const{locationSettings:a}=qt();return r(Ds,{children:[n,r("div",{"data-loading":!0,children:[t(ks,{children:"Created at:"}),t("span",{children:Qn(Ht(e.createdAt),a.locale)})]})]})},Ps=d(rt,{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}})),Bs=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Ps,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(Xn,{}),elseShow:t(Zn,{})})}),Ms=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Os=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),_s=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:c,enabled:l}=e,p=A("projectId"),u=A("featureId"),{feature:g,refetchFeature:h}=V(p,u),S=r(_,{children:[" ",r("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(ct,{text:c,maxWidth:"120",maxLength:15})]}),b=()=>{h(),n&&n()};return r(Ms,{children:[r(Os,{children:[t(Ua,{featureId:g.name,projectId:p,environmentName:e.name,onToggle:b,onError:a,value:l}),s??S]}),t(Bs,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i})]})},Ls=d("div")(({theme:e})=>({padding:e.spacing(3)})),js=d("div")(()=>({display:"flex",flexDirection:"column"})),Vs=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),zs=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Dt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Ws=d(dt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),Ns=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:s})=>{const[o,i]=f.useState(!1),[c,l]=f.useState(""),p=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return r(Ls,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],S=h.length>0&&r(_,{children:[t(Dt,{}),t(X,{title:"View variants",arrow:!0,describeChild:!0,children:t(Ws,{component:Y,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),b=u.enabled&&h.length===0&&p;return t(_s,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(u.name),i(!0)},children:r(js,{children:[t(Vs,{children:u.name}),r(zs,{children:[g,S,t(E,{condition:b,show:r(_,{children:[t(Dt,{}),t(Ga,{})]})})]})]})},u.name)}),t(Ya,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:c})]})},ln=(e,n={})=>{const a=async()=>{const u=Te(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Be("Tags"))).json()},s=`api/admin/features/${e}/tags`,{data:o,error:i}=ea(!!e,{tags:[]},s,a,n),[c,l]=f.useState(!i&&!o),p=()=>{st(s)};return f.useEffect(()=>{l(!i&&!o)},[o,i]),{tags:(o==null?void 0:o.tags)||[],error:i,loading:c,refetch:p}},qs=d("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),Qe=e=>e.map(n=>({title:n.value})),kt=(e,n)=>e.map(a=>({value:a.title,type:n})),dn=({open:e,setOpen:n})=>{const{tagTypes:a}=ta(),s=A("featureId"),{createTag:o}=Ka(),{updateFeatureTags:i,loading:c}=Le(),{tags:l,refetch:p,loading:u}=ln(s),{setToastData:g}=U(),h=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[S,b]=f.useState(h),C=c||u,[R,y]=f.useState(0),{trackEvent:m}=_e(),[T,F]=f.useState(Qe(l.filter(v=>v.type===S.name))),{tags:$,refetch:j}=Ja(S.name),k=f.useMemo(()=>Qe($),[$]);f.useEffect(()=>{l&&S&&F(Qe(l.filter(v=>v.type===S.name)))},[JSON.stringify(l),S]);const P=()=>{n(!1),F([])};function B(v,I){const O=v.filter(L=>L.type===S.name).filter(L=>!I.find(z=>L.value===z.value&&L.type===z.type)),W=I.filter(L=>L.type===S.name).filter(L=>!v.find(z=>L.value===z.value&&L.type===z.type));return y(O.length+W.length),{added:O,removed:W}}const G=v=>v.filter(I=>!I.title.startsWith("Create")),K=async(v,I)=>{try{await i(s,{addedTags:v,removedTags:I}),await p()}catch(O){const W=N(O);g({type:"error",title:"Failed to add tag",text:W,confetti:!1})}},te=(v,I)=>{let O="We successfully";return v>0&&(O=O.concat(` added ${v} new tag${v>1?"s":""}`)),v>0&&I>0&&(O=O.concat(" and ")),I>0&&(O=O.concat(` removed ${I} tag${I>1?"s":""}`)),O},ce=async v=>{v.preventDefault();const I=kt(G(T),S.name),{added:O,removed:W}=B(I,l);R>0&&(await K(O,W),R>1&&m("suggest_tags",{props:{eventType:"multiple_tags_added"}}),R>0&&g({type:"success",title:`Updated tag${O.length>1?"s":""} to toggle`,text:te(O.length,W.length),confetti:!0})),y(0),F([]),n(!1)},w=(v,I)=>{I!=null&&typeof I!="string"&&(v.preventDefault(),b(I),F([]),y(0))},M=(v,I,O)=>{const W=na(I);O==="selectOption"&&I.forEach((z,Ae)=>{if(typeof z!="string"&&z.inputValue&&z.inputValue!==""){const Re={value:z.inputValue,type:S.name};o(Re).then(()=>{m("suggest_tags",{props:{eventType:"tag_created"}}),j()}),z.title=z.inputValue,z.inputValue="",W[Ae]=z}});const L=kt(G(W),S.name);B(L,l),F(W)},D="add-tag-form";return t(ae,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:ce,disabledPrimaryButton:C||R===0,onClose:P,formId:D,children:r(_,{children:[t(q,{paragraph:!0,sx:{marginBottom:v=>v.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:D,onSubmit:ce,children:r(qs,{children:[t(Qa,{options:a,value:S,onChange:w}),t(Xa,{options:k,existingTags:l,tagType:S,selectedOptions:T,onChange:M})]})})]})})},Hs=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Us=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Gs=d(Ut)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Ys=d(Ce)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Ks=d(me)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Js=({feature:e,header:n})=>{const{tags:a,refetch:s}=ln(e.name),{deleteTagFromFeature:o}=Le(),[i,c]=f.useState(!1),[l,p]=f.useState(!1),[u,g]=f.useState(),{setToastData:h,setToastApiError:S}=U(),{hasAccess:b}=f.useContext(it),C=b(pe,e.project),R=async()=>{if(u)try{await o(e.name,u.type,u.value),s(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){S(N(y))}};return r(Hs,{children:[n,t(Us,{children:a.map(y=>{const m=`${y.type}:${y.value}`;return t(Gs,{label:m,deleteIcon:t(aa,{titleAccess:"Remove"}),onDelete:C?()=>{p(!0),g(y)}:void 0},m)})}),t(E,{condition:C,show:r(_,{children:[t(E,{condition:a.length>0,show:t(Ys,{})}),t(Ks,{"data-loading":!0,variant:"outlined",startIcon:t(oa,{}),onClick:()=>c(!0),children:"Add new tag"})]})}),t(dn,{open:i,setOpen:c}),r(ae,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{p(!1),g(void 0)},onClick:()=>{p(!1),R(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",r("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},Qs=d("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),Xe=d("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}})),Xs=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=A("projectId"),s=A("featureId"),{feature:o}=V(a,s);return r(Qs,{children:[t(Ns,{header:r(Xe,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:i})=>i).length,")",t(sa,{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(Ce,{}),t($s,{header:t(Xe,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(Ce,{}),t(Js,{header:t(Xe,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},Zs=()=>{const{trackEvent:e}=_e(),{value:n,setValue:a}=Nt(),[s,o]=f.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:s,setHiddenEnvironments:c=>{a(l=>{const p=new Set(l.hiddenEnvironments);return p.has(c)?(p.delete(c),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(p.add(c),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(p),{...n,hiddenEnvironments:p}})}}},er=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),tr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),nr=()=>{const e=re(),n=A("projectId"),a=A("featureId"),s=Vt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=Zs(),c=()=>e(s);return Gt(a),r(er,{children:[r("div",{children:[t(ho,{}),t(Xs,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(tr,{children:t(Fs,{})}),r(Yt,{children:[t(ne,{path:"strategies/create",element:t(tt,{label:"Create feature strategy",onClose:c,open:!0,children:t(Za,{})})}),t(ne,{path:"strategies/edit",element:t(tt,{label:"Edit feature strategy",onClose:c,open:!0,children:t(ra,{})})})]})]})},ar=d("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})),or=d(Kt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),sr=d("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})),rr=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ir=d(ie)(({theme:e})=>({marginBottom:e.spacing(2)})),cr=d(ie)(({theme:e})=>({marginTop:e.spacing(4)})),lr=d("div")({display:"flex",flexDirection:"column"}),dr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),$t=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ur=d(Ce)(({theme:e})=>({margin:e.spacing(4,0)})),pr=d(ia)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),gr=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),hr=d(me)(({theme:e})=>({marginLeft:e.spacing(3)})),fr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const c=A("projectId"),l=A("featureId"),{uiConfig:p}=Jt(),{context:u}=ca(),{defaultStickiness:g,loading:h}=la(c),{isChangeRequestConfigured:S}=se(c),{data:b}=fe(c),{changeRequestInReviewOrApproved:C,alert:R}=ga(b),y=(e==null?void 0:e.variants)||[],[m,T]=f.useState([]),[F,$]=f.useState();f.useEffect(()=>{h||T(y.length?y.map(x=>({...x,isValid:!0,new:!1,id:ze()})):[{name:"",weightType:gt.VARIABLE,weight:0,overrides:[],stickiness:(m==null?void 0:m.length)>0?m[0].stickiness:g,new:!0,isValid:!1,id:ze()}])},[n,h]);const j=(x,H)=>{T(le=>ht(le.map(Ie=>Ie.id===H?x:Ie),1e3))},k=()=>{const x=ze();T(H=>[...H,{name:"",weightType:gt.VARIABLE,weight:0,overrides:[],stickiness:(H==null?void 0:H.length)>0?H[0].stickiness:g,new:!0,isValid:!1,id:x}]),$(x)};f.useEffect(()=>{if(F){const x=document.getElementById(`variant-name-input-${F}`);x==null||x.scrollIntoView({behavior:"smooth",block:"center"}),x==null||x.focus({preventScroll:!0}),$(void 0)}},[F]);const P=m.map(({new:x,isValid:H,id:le,...Ie})=>Ie),B=s(y,P),G=o(P),K=async x=>{x.preventDefault(),i(P)},te=()=>D?`curl --location --request POST '${p.unleashUrl}/api/admin/projects/${c}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
1
|
+
import{c as Lt,j as t,s as d,aD as A,aE as V,aF as pn,d as r,aG as gn,C as E,aH as Z,aI as pe,aJ as Y,aK as ye,aL as hn,aM as ot,r as f,aN as Te,aO as Be,aP as st,aQ as fn,aR as mn,aS as yn,aT as Sn,f as U,aU as Me,aV as fe,h as N,T as q,aW as we,aX as xe,aY as bn,aZ as se,a_ as ge,a$ as X,t as rt,b0 as Cn,b1 as vn,b2 as Ee,M as he,b3 as $e,b4 as jt,b5 as Se,b6 as ae,au as re,E as ie,b7 as Vt,b8 as Tn,b9 as wn,ba as xn,bb as En,bc as et,bd as An,be as Rn,y as _,B as J,bf as In,bg as Fn,bh as Dn,bi as kn,bj as $n,bk as Pn,bl as Bn,bm as Mn,bn as On,G as _n,b as zt,aa as Oe,x as be,bo as it,i as me,N as ct,bp as Wt,ag as _e,V as Ln,bq as lt,br as ue,bs as oe,bt as jn,$ as Vn,bu as zn,bv as ee,bw as Wn,bx as Nn,R as qn,by as Hn,bz as Un,bA as Gn,bB as Yn,bC as Nt,bD as Kn,bE as Jn,bF as qt,bG as Qn,bH as Ht,bI as Xn,bJ as Zn,bK as dt,bL as ea,bM as ta,bN as Le,bO as na,L as Ut,D as Ce,bP as aa,bQ as oa,bR as sa,bS as Gt,bT as Yt,bU as ne,bV as tt,bW as ra,bX as Kt,bY as ia,X as Jt,g as ca,bZ as la,b_ as ze,b$ as gt,as as da,ax as ua,c0 as de,c1 as pa,c2 as ht,c3 as ga,c4 as ha,m as fa,aq as ut,ar as ma,al as ft,c5 as ya,c6 as Sa,c7 as ba,c8 as mt,a9 as Qt,c9 as Ca,a1 as We,ac as va,a3 as Ta,a4 as wa,a5 as xa,a6 as Ea,a7 as Aa,a8 as Ra,ca as Ia,cb as yt,cc as Fa,cd as Xt,ce as Da,q as ka,cf as St,cg as $a,ch as Pa,ci as Ba,cj as Ma,ck as Oa,cl as _a,ai as La,cm as ja,cn as Va,co as za,cp as Wa,cq as Na,cr as qa}from"./index-1c4c68c3.js";import{C as Zt,f as en,E as Ha,F as Ua,V as Ga,a as Ya,u as Ka,b as Ja,T as Qa,c as Xa,d as Za,W as eo,e as to,g as no}from"./FeatureArchiveDialog-9ad60db1.js";import{S as ao}from"./StrategyItemContainer-88c18285.js";const oo=Lt(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"),so=Lt(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=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),io=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n);return a.name?t(ro,{children:t(pn,{title:"Event log",feature:n,displayInline:!0})}):null},co=d("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"}})),lo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),uo=d("div")({display:"flex",alignItems:"center"}),po=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),go=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),bt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Ct=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),ho=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n),{project:s,description:o,type:i}=a,c=hn(i);return t(co,{children:r(lo,{children:[r(uo,{"data-loading":!0,children:[t(c,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",r(po,{children:[gn(i||"")," toggle"]})]}),r(go,{children:[r(bt,{"data-loading":!0,children:["Project: ",s]}),t(E,{condition:!!o,show:r(bt,{"data-loading":!0,children:[t("div",{children:"Description:"}),r(Ct,{children:[t("p",{children:o}),t(Z,{projectId:e,permission:pe,component:Y,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:r(Ct,{children:["No description."," ",t(Z,{projectId:e,permission:pe,component:Y,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},vt={lastHourUsage:[],seenApplications:[]},fo=(e,n,a={})=>{const s=async()=>{const g=Te(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Be("feature metrics"));return h.ok?h.json():vt},o=`${e}_${n}_metrics`,{data:i,error:c}=ot(o,s,{...a}),[l,p]=f.useState(!c&&!i),u=()=>{st(o)};return f.useEffect(()=>{p(!c&&!i)},[i,c]),{metrics:i||vt,error:c,loading:l,refetch:u,FEATURE_METRICS_CACHE_KEY:o}},mo=e=>({yes:0,no:0,environment:e,timestamp:""}),yo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||mo(a.name)),So=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s)),bo=fn(ot,So),tn=(e,n)=>{const{refetchFeature:a}=V(e,n),s=mn(e,n),{data:o,error:i,mutate:c}=bo(["useFeatureImmutable",s],()=>yn(s)),l=f.useCallback(async()=>{await c(),await a()},[c,a]);return{feature:(o==null?void 0:o.body)||Sn,refetchFeature:l,loading:!i&&!o,status:o==null?void 0:o.status,error:i}},nn=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=U(),{addChange:i}=Me(),{refetch:c}=fe(e),[l,p]=f.useState({isOpen:!1}),u=f.useCallback((C,R,y)=>{p({featureName:n,environment:C,fromEnvironment:y,strategy:R,isOpen:!0})},[]),g=f.useCallback((C,R,y)=>{p({featureName:n,environment:C,fromEnvironment:y,strategies:R,isOpen:!0})},[]),h=f.useCallback(()=>{p({isOpen:!1})},[]),S=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),c(),p({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(C){o(N(C)),p({isOpen:!1})}},[i]),b=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(C=>i(e,l.environment,{feature:l.featureName,action:a,payload:C}))),c(),p({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(C){o(N(C)),p({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategiesConfirm:b,changeRequestDialogDetails:l}},Co=({payload:e,fromEnvironment:n,environment:a})=>r(q,{children:[r("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),vo=({environmentId:e,environments:n,strategy:a})=>{const s=A("projectId"),o=A("featureId"),[i,c]=f.useState(null),l=!!i,{addStrategyToFeature:p}=xe(),{setToastData:u,setToastApiError:g}=U(),{refetchFeature:h}=V(s,o),{refetchFeature:S}=tn(s,o),b=()=>{c(null)},C=bn(s),{isChangeRequestConfigured:R}=se(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:m,onChangeRequestAddStrategy:T,onChangeRequestAddStrategyConfirm:F}=nn(s,o,"addStrategy"),$=async k=>{const{id:P,...B}={...a,targetEnvironment:k};if(R(k)){await T(k,{id:P,...B},e);return}try{await p(s,o,k,a),h(),S(),u({title:"Strategy created",text:`Successfully copied a strategy to ${k}`,type:"success"})}catch(G){g(N(G))}b()},j=n.some(k=>C(ge,k));return r("div",{children:[t(Zt,{isOpen:y.isOpen,onClose:m,environment:y==null?void 0:y.environment,onConfirm:F,messageComponent:t(Co,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(X,{title:`Copy to another environment${j?"":" (Access denied)"}`,children:t("div",{children:t(rt,{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:k=>{c(k.currentTarget)},"data-testid":Cn,disabled:!j,children:t(vn,{})})})}),t(Ee,{id:"basic-menu",anchorEl:i,open:l,onClose:b,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(k=>{const P=C(ge,k);return t(X,{title:P?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(he,{onClick:()=>$(k),disabled:!P,children:[t(E,{condition:!P,show:t($e,{children:t(jt,{fontSize:"small"})})}),r(Se,{children:["Copy to ",k]})]})})},k)})})]})},an=()=>t(ie,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),To=({onRemove:e,onClose:n,isOpen:a})=>t(ae,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(an,{})}),wo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),xo=({onRemove:e,onClose:n,isOpen:a})=>r(ae,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(an,{}),t(wo,{children:t(q,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(q,{fontWeight:"bold",children:"Remove strategy"})]}),Eo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=xe(),{setToastData:i,setToastApiError:c}=U(),l=re(),{refetchFeature:p}=V(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),p(),l(Vt(e,n))}catch(h){c(N(h))}}},Ao=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=Me(),{refetch:i}=fe(e),{setToastData:c,setToastApiError:l}=U();return async u=>{try{u.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(N(g))}}},Ro=({projectId:e,featureId:n,environmentId:a,strategyId:s,text:o,isOpen:i,onClose:c})=>{const{isChangeRequestConfigured:l}=se(e),p=Eo({featureId:n,projectId:e,strategyId:s,environmentId:a}),u=Ao({featureId:n,projectId:e,strategyId:s,environmentId:a});return l(a)?t(xo,{isOpen:i,onClose:()=>c(),onRemove:async g=>{await u(g),c()}}):t(To,{isOpen:i,onClose:()=>c(),onRemove:p})},Io=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=V(e,a),{setStrategyDisabledState:i}=xe(),{setToastData:c,setToastApiError:l}=U(),p=u=>async()=>{try{await i(e,a,n,s.id,!u),c({title:`Strategy ${u?"enabled":"disabled"}`,type:"success"}),o()}catch(g){l(N(g))}};return{onDisable:p(!1),onEnable:p(!0)}},Fo=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=Me(),{refetch:i}=fe(e),{setToastData:c,setToastApiError:l}=U(),p=u=>async()=>{try{await o(e,n,{action:"updateStrategy",feature:a,payload:{...s,disabled:!u}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(N(g))}};return{onSuggestDisable:p(!1),onSuggestEnable:p(!0)}},Do=({isOpen:e,onClose:n,...a})=>{var b;const{projectId:s,environmentId:o}=a,{isChangeRequestConfigured:i}=se(s),c=i(o),{onSuggestEnable:l,onSuggestDisable:p}=Fo({...a}),{onEnable:u,onDisable:g}=Io({...a}),h=!!((b=a.strategy)!=null&&b.disabled);return t(ae,{title:c?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:c?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:C=>{C.preventDefault(),c?h?l():p():h?u():g(),n()},onClose:()=>n(),children:t(E,{condition:c,show:t(Tn,{environment:o}),elseShow:r(ie,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var pt={},ko=xn;Object.defineProperty(pt,"__esModule",{value:!0});var on=pt.default=void 0,$o=ko(wn()),Po=En,Bo=(0,$o.default)((0,Po.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");on=pt.default=Bo;const Mo=({projectId:e,strategy:n,featureId:a,environmentId:s})=>{const[o,i]=f.useState(null),[c,l]=f.useState(!1),[p,u]=f.useState(!1),g=!!o,h=R=>{i(R.currentTarget)},S=R=>{i(null),R.stopPropagation()},b=et(An,e,s),C=et(Rn,e,s);return r(_,{children:[t(J,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(X,{title:"More actions",children:t(rt,{onClick:h,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":In,children:t(Fn,{sx:{width:32,height:32}})})})}),r(Ee,{anchorEl:o,id:"actions-menu",open:g,onClose:S,onClick:S,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Dn,children:[t(X,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:r(he,{disabled:!b,onClick:()=>l(!0),children:[t($e,{children:n.disabled?t(kn,{}):t($n,{})}),t(Se,{children:n.disabled?"Enable":"Disable"})]})}),t(X,{title:"Remove strategy",arrow:!0,placement:"left",children:r(he,{disabled:!C,onClick:()=>u(!0),"data-testid":Pn,children:[t($e,{children:t(on,{})}),t(Se,{children:"Remove"})]})})]}),t(Do,{isOpen:c,onClose:()=>l(!1),projectId:e,featureId:a,environmentId:s,strategy:n}),t(Ro,{isOpen:p,onClose:()=>u(!1),projectId:e,featureId:a,environmentId:s,strategyId:n.id})]})},Oo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:c})=>{const l=A("projectId"),p=A("featureId"),u=Bn(l,p,e,n.id);return t(ao,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:r(_,{children:[c,t(E,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t(vo,{environmentId:e,environments:o,strategy:n})}),t(Z,{permission:Mn,environmentId:e,projectId:l,component:Y,to:u,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(ye,{})}),t(Mo,{projectId:l,featureId:p,environmentId:e,strategy:n})]}),children:t(On,{strategy:n})})},_o=(e,n,a,s)=>{const{data:o}=fe(e),i=o==null?void 0:o.find(p=>p.environment===a),c=i==null?void 0:i.features.find(p=>p.name===n);return c==null?void 0:c.changes.find(p=>p.action==="updateStrategy"||p.action==="deleteStrategy"?p.payload.id===s:!1)},Lo=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:c,onDragEnd:l})=>{const p=A("projectId"),u=A("featureId"),g=f.useRef(null),h=_o(p,u,a,e.id);return r(J,{ref:g,onDragOver:c(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(_n,{text:"OR"})}),t(Oo,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(g,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(jo,{change:h})})]},e.id)},jo=({change:e})=>{const n=zt();return Oe(n.breakpoints.down("sm"))?null:r(J,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(be,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(be,{color:"error",children:"Deleted in draft"})})]})},Vo=({environmentId:e,environments:n,onClick:a})=>{const s=A("projectId"),[o,i]=f.useState(null),c=!!o,{hasAccess:l}=f.useContext(it),p=n.some(u=>l(ge,s,u));return r("div",{children:[t(X,{title:p?"":"(Access denied)",children:t("div",{children:t(me,{id:`copy-all-strategies-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:u=>{i(u.currentTarget)},disabled:!p,variant:"outlined",children:"Copy from another environment"})})}),t(Ee,{id:"basic-menu",anchorEl:o,open:c,onClose:()=>{i(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=l(ge,s,u);return t(X,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(he,{onClick:()=>a(u),disabled:!g,children:[t(E,{condition:!g,show:t($e,{children:t(jt,{fontSize:"small"})})}),r(Se,{children:["Copy from ",u]})]})})},u)})})]})},zo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Wo=({payload:e,fromEnvironment:n,environment:a})=>r(zo,{children:[t(q,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>r(q,{children:[r("strong",{children:[we((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),r(q,{children:["from ",n," to ",a]})]}),No=d("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}})),qo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Ho=d(ct)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Uo=d(Y)(({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}})),Ne=({projectId:e,featureId:n,environmentId:a,strategy:s,defaultStrategy:o})=>{const i=Wt(s.name),c=we(s.name),{trackEvent:l}=_e(),p=en(e,n,a,s.name,o);return r(Uo,{to:p,onClick:()=>{l("strategy-add",{props:{buttonTitle:s.displayName||c}})},children:[t(No,{children:t(i,{})}),r("div",{children:[t(Ho,{text:s.displayName||c,maxWidth:"200",maxLength:25}),t(qo,{children:s.description})]})]})},qe=d(q)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),Go=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=Ln(),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(lt,{dense:!0,children:[r(_,{children:[r(qe,{color:"textSecondary",children:[a," environment default strategy"]}),t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:c,defaultStrategy:!0})},c.name)]}),t(qe,{color:"textSecondary",children:"Predefined strategy types"}),o.map(l=>t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name)),t(E,{condition:i.length>0,show:r(_,{children:[t(qe,{color:"textSecondary",children:"Custom strategies"}),i.map(l=>t(ue,{children:t(Ne,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))]})})]})},Yo=d("div")({flexShrink:0}),Ko=d(oe)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),nt=({label:e,projectId:n,featureId:a,environmentId:s,variant:o,size:i,matchWidth:c})=>{const[l,p]=f.useState(),u=re(),{trackEvent:g}=_e(),h=!!l,S=h?"FeatureStrategyMenuPopover":void 0,b=()=>{p(void 0)},C=m=>{g("strategy-add",{props:{buttonTitle:e}}),u(y)},R=m=>{p(m.currentTarget)},y=en(n,a,s,"flexibleRollout",!0);return r(Yo,{onClick:m=>m.stopPropagation(),children:[t(oe,{permission:ge,projectId:n,environmentId:s,onClick:C,"aria-labelledby":S,variant:o,size:i,sx:{minWidth:c?"282px":"auto"},children:e}),t(Ko,{permission:ge,projectId:n,environmentId:s,onClick:R,"aria-labelledby":S,variant:"outlined",size:i,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(jn,{sx:m=>({margin:m.spacing(.25,0)})})}),t(Vn,{id:S,open:h,anchorEl:l,onClose:b,onClick:b,PaperProps:{sx:m=>({paddingBottom:m.spacing(1)})},children:t(Go,{projectId:n,featureId:a,environmentId:s})})]})},Jo=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Qo=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Xo=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),Zo=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=xe(),{setToastData:o,setToastApiError:i}=U(),{refetchFeature:c}=V(e,n),{refetchFeature:l}=tn(e,n),{feature:p}=V(e,n),u=p==null?void 0:p.environments.filter(T=>T.name!==a&&T.strategies&&T.strategies.length>0),{isChangeRequestConfigured:g}=se(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:S,onChangeRequestAddStrategiesConfirm:b,onChangeRequestAddStrategyClose:C}=nn(e,n,"addStrategy"),R=(T=!1)=>{c(),l(),o({title:T?"Strategies created":"Strategy created",text:T?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async T=>{var $;const F=(($=u==null?void 0:u.find(j=>j.name===T))==null?void 0:$.strategies)||[];if(g(a)){await S(a,F,T);return}try{await Promise.all(F.map(j=>{const{id:k,...P}={...j,environment:a};return s(e,n,a,P)})),R(!0)}catch(j){i(N(j))}},m=u&&u.length>0;return r(_,{children:[t(Zt,{isOpen:h.isOpen,onClose:C,environment:h==null?void 0:h.environment,onConfirm:b,messageComponent:t(Wo,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),r(Jo,{children:[t(Qo,{children:"You have not defined any strategies yet."}),r(Xo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(Y,{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(nt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:m}),t(E,{condition:m,show:t(Vo,{environmentId:a,environments:u.map(T=>T.name),onClick:y})})]})]})]})},es=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ts=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ns=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=A("projectId"),o=A("featureId"),{setStrategiesSortOrder:i}=xe(),{setToastData:c,setToastApiError:l}=U(),{refetchFeature:p}=V(s,o),[u,g]=f.useState((e==null?void 0:e.strategies)||[]),[h,S]=f.useState(null);if(f.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const b=async m=>{try{await i(s,o,e.name,m),p(),c({title:"Order of strategies updated",type:"success"})}catch(T){l(N(T))}},C=(m,T)=>F=>{var $;S({id:u[T].id,index:T,height:(($=m.current)==null?void 0:$.offsetHeight)||0}),m!=null&&m.current&&(F.dataTransfer.effectAllowed="move",F.dataTransfer.setData("text/html",m.current.outerHTML),F.dataTransfer.setDragImage(m.current,20,20))},R=m=>(T,F)=>$=>{if(h===null||T.current===null||h.index===F||m===h.id)return;const{top:j,bottom:k}=T.current.getBoundingClientRect(),P=$.clientY-j<h.height,B=k-$.clientY<h.height,G=h.index>F;if(P&&G||B&&!G){const K=[...u],te=K.splice(h.index,1)[0];K.splice(F,0,te),g(K),S({...h,index:F})}},y=()=>{S(null),b(u.map((m,T)=>({id:m.id,sortOrder:T})))};return t(es,{children:r(ts,{children:[t(E,{condition:u.length>0&&n,show:()=>t(ie,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:u.length>0,show:t(_,{children:u.map((m,T)=>t(Lo,{strategy:m,index:T,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===m.id,onDragStartRef:C,onDragOver:R(m.id),onDragEnd:y},m.id))}),elseShow:t(Zo,{projectId:s,featureId:o,environmentId:e.name})})]})})},sn=(e,n)=>e===0?0:Math.round(n/e*100);var je={},Ve={};Object.defineProperty(Ve,"__esModule",{value:!0});Ve.defaultOptions=void 0;Ve.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var Q={};Object.defineProperty(Q,"__esModule",{value:!0});Q.getLocales=Q.getFractionDigits=Q.roundTo=Q.parseValue=void 0;function as(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}Q.parseValue=as;function os(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))}Q.roundTo=os;function ss(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}Q.getFractionDigits=ss;function rs(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}Q.getLocales=rs;Object.defineProperty(je,"__esModule",{value:!0});je.millify=void 0;const Tt=Ve,Fe=Q,wt=1e3;function*xt(e){let n=wt;for(;;){const a=e/n;if(a<1)return;yield a,n*=wt}}function rn(e,n){var a,s;const o=n?{...Tt.defaultOptions,...n}:Tt.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let i;try{i=Fe.parseValue(e)}catch(C){return C instanceof Error&&console.warn(`WARN: ${C.message} (millify)`),String(e)}const c=i<0?"-":"";i=Math.abs(i);let l=0;for(const C of xt(i))i=C,l+=1;if(l>=o.units.length)return e.toString();let u=Fe.roundTo(i,o.precision);for(const C of xt(u))u=C,l+=1;const g=(a=o.units[l])!==null&&a!==void 0?a:"",h=o.lowercase?g.toLowerCase():g,S=o.space?" ":"",b=u.toLocaleString((s=o.locales)!==null&&s!==void 0?s:Fe.getLocales(),{minimumFractionDigits:Fe.getFractionDigits(u)});return`${c}${b}${S}${h}`}je.millify=rn;var is=je.default=rn;const Pe=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=is(e,{precision:a}),o=!0);const i=t("span",{"data-testid":zn,children:s});return t(E,{condition:o,show:t(X,{title:e.toLocaleString(),arrow:!0,children:i}),elseShow:i})},He=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Ue=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),Ge=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),Ye=d("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})),cn=({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(ee,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Exposure"}),t(Ge,{children:t(Pe,{value:e})}),r(Ye,{children:["Total exposure of the feature in the environment"," ",i,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Exposure %"}),r(Ge,{children:[sn(e+n,e),"%"]}),r(Ye,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:r(He,{children:[t(Ue,{children:"Requests"}),t(Ge,{children:t(Pe,{value:e+n})}),r(Ye,{children:["Total requests for the feature in the environment"," ",i,"."]})]})})]})},cs=d("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}})),ls=d("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})),ds=({children:e})=>t(cs,{children:t(ls,{children:e})}),us=({environmentMetric:e})=>e?r(_,{children:[t(ds,{children:"Feature toggle exposure"}),t("div",{children:t(cn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Et=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),At=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Rt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),It=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),ps=d(Wn)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),gs=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),hs=({environmentMetric:e,disabled:n=!1})=>{const a=Nn();if(!e)return null;const s=e.yes+e.no,o=sn(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?r(Et,{children:[r(At,{children:[r(Rt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),r(It,{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(Et,{children:[r(At,{children:[r(Rt,{children:[o,"%"]}),r(It,{children:["The feature has been requested"," ",r("b",{children:[t(Pe,{value:s})," times"]})," ","and exposed"," ",r("b",{children:[t(Pe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(gs,{"data-loading":!0,children:t(qn,{percentage:o,size:"3rem"})})]})},Ke=({strategy:e})=>{const n=Wt(e.name);return t(X,{title:we(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t(fs,{children:t(n,{})})})},fs=d("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)}})),Ft=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Je=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),ms=d("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),De=5,ys=({strategies:e})=>e!=null&&e.length?e.length>De+1?r(Ft,{"aria-label":"Feature strategies",children:[e.slice(0,De).map(n=>t(Je,{children:t(Ke,{strategy:n})},n.id)),r(Hn,{tooltip:e.slice(De).map(n=>t(Je,{children:r(ms,{children:[t(Ke,{strategy:n})," ",we(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-De,")"]})]}):t(Ft,{"aria-label":"Feature strategies",children:e.map(n=>t(Je,{children:t(Ke,{strategy:n})},n.id))}):null,Ss=d("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})),bs=d(Un)({boxShadow:"none",background:"none"}),Cs=d(Gn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),vs=d(Yn,{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)}})),Ts=d(ns)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ws=d("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})),xs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Es=d(Ha)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),As=d(ct)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Rs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),Is=({env:e})=>{var u;const n=A("projectId"),a=A("featureId"),{metrics:s}=fo(n,a),{feature:o}=V(n,a),{value:i}=Nt(),l=yo(o==null?void 0:o.environments,s).find(g=>g.environment===e.name),p=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!new Set(i.hiddenEnvironments).has(e.name),show:t(Ss,{enabled:e.enabled,children:r(bs,{"data-testid":`${Kn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[r(Cs,{expandIcon:t(Jn,{titleAccess:"Toggle"}),children:[r(ws,{"data-loading":!0,enabled:e.enabled,children:[r(xs,{children:[t(Es,{enabled:e.enabled}),t("div",{children:t(As,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(be,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),r(Rs,{children:[t(nt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"}),t(ys,{strategies:p==null?void 0:p.strategies})]})]}),t(hs,{environmentMetric:l,disabled:!e.enabled})]}),r(vs,{enabled:e.enabled,children:[t(Ts,{featureEnvironment:p,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((u=p==null?void 0:p.strategies)==null?void 0:u.length)||0)>0,show:r(_,{children:[t(J,{sx:{display:"flex",justifyContent:"center",py:1},children:t(nt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(us,{environmentMetric:l})]})})]})]})})})},Fs=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=V(e,n);if(!a)return null;const{environments:s}=a;return t(_,{children:s==null?void 0:s.map(o=>t(Is,{env:o},o.name))})},Ds=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),ks=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),$s=({feature:e,header:n})=>{const{locationSettings:a}=qt();return r(Ds,{children:[n,r("div",{"data-loading":!0,children:[t(ks,{children:"Created at:"}),t("span",{children:Qn(Ht(e.createdAt),a.locale)})]})]})},Ps=d(rt,{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}})),Bs=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Ps,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(Xn,{}),elseShow:t(Zn,{})})}),Ms=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Os=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),_s=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:c,enabled:l}=e,p=A("projectId"),u=A("featureId"),{feature:g,refetchFeature:h}=V(p,u),S=r(_,{children:[" ",r("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(ct,{text:c,maxWidth:"120",maxLength:15})]}),b=()=>{h(),n&&n()};return r(Ms,{children:[r(Os,{children:[t(Ua,{featureId:g.name,projectId:p,environmentName:e.name,onToggle:b,onError:a,value:l}),s??S]}),t(Bs,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i})]})},Ls=d("div")(({theme:e})=>({padding:e.spacing(3)})),js=d("div")(()=>({display:"flex",flexDirection:"column"})),Vs=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),zs=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Dt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Ws=d(dt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),Ns=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:s})=>{const[o,i]=f.useState(!1),[c,l]=f.useState(""),p=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return r(Ls,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],S=h.length>0&&r(_,{children:[t(Dt,{}),t(X,{title:"View variants",arrow:!0,describeChild:!0,children:t(Ws,{component:Y,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),b=u.enabled&&h.length===0&&p;return t(_s,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(u.name),i(!0)},children:r(js,{children:[t(Vs,{children:u.name}),r(zs,{children:[g,S,t(E,{condition:b,show:r(_,{children:[t(Dt,{}),t(Ga,{})]})})]})]})},u.name)}),t(Ya,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:c})]})},ln=(e,n={})=>{const a=async()=>{const u=Te(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Be("Tags"))).json()},s=`api/admin/features/${e}/tags`,{data:o,error:i}=ea(!!e,{tags:[]},s,a,n),[c,l]=f.useState(!i&&!o),p=()=>{st(s)};return f.useEffect(()=>{l(!i&&!o)},[o,i]),{tags:(o==null?void 0:o.tags)||[],error:i,loading:c,refetch:p}},qs=d("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),Qe=e=>e.map(n=>({title:n.value})),kt=(e,n)=>e.map(a=>({value:a.title,type:n})),dn=({open:e,setOpen:n})=>{const{tagTypes:a}=ta(),s=A("featureId"),{createTag:o}=Ka(),{updateFeatureTags:i,loading:c}=Le(),{tags:l,refetch:p,loading:u}=ln(s),{setToastData:g}=U(),h=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[S,b]=f.useState(h),C=c||u,[R,y]=f.useState(0),{trackEvent:m}=_e(),[T,F]=f.useState(Qe(l.filter(v=>v.type===S.name))),{tags:$,refetch:j}=Ja(S.name),k=f.useMemo(()=>Qe($),[$]);f.useEffect(()=>{l&&S&&F(Qe(l.filter(v=>v.type===S.name)))},[JSON.stringify(l),S]);const P=()=>{n(!1),F([])};function B(v,I){const O=v.filter(L=>L.type===S.name).filter(L=>!I.find(z=>L.value===z.value&&L.type===z.type)),W=I.filter(L=>L.type===S.name).filter(L=>!v.find(z=>L.value===z.value&&L.type===z.type));return y(O.length+W.length),{added:O,removed:W}}const G=v=>v.filter(I=>!I.title.startsWith("Create")),K=async(v,I)=>{try{await i(s,{addedTags:v,removedTags:I}),await p()}catch(O){const W=N(O);g({type:"error",title:"Failed to add tag",text:W,confetti:!1})}},te=(v,I)=>{let O="We successfully";return v>0&&(O=O.concat(` added ${v} new tag${v>1?"s":""}`)),v>0&&I>0&&(O=O.concat(" and ")),I>0&&(O=O.concat(` removed ${I} tag${I>1?"s":""}`)),O},ce=async v=>{v.preventDefault();const I=kt(G(T),S.name),{added:O,removed:W}=B(I,l);R>0&&(await K(O,W),R>1&&m("suggest_tags",{props:{eventType:"multiple_tags_added"}}),R>0&&g({type:"success",title:`Updated tag${O.length>1?"s":""} to toggle`,text:te(O.length,W.length),confetti:!0})),y(0),F([]),n(!1)},w=(v,I)=>{I!=null&&typeof I!="string"&&(v.preventDefault(),b(I),F([]),y(0))},M=(v,I,O)=>{const W=na(I);O==="selectOption"&&I.forEach((z,Ae)=>{if(typeof z!="string"&&z.inputValue&&z.inputValue!==""){const Re={value:z.inputValue,type:S.name};o(Re).then(()=>{m("suggest_tags",{props:{eventType:"tag_created"}}),j()}),z.title=z.inputValue,z.inputValue="",W[Ae]=z}});const L=kt(G(W),S.name);B(L,l),F(W)},D="add-tag-form";return t(ae,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:ce,disabledPrimaryButton:C||R===0,onClose:P,formId:D,children:r(_,{children:[t(q,{paragraph:!0,sx:{marginBottom:v=>v.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:D,onSubmit:ce,children:r(qs,{children:[t(Qa,{options:a,value:S,onChange:w}),t(Xa,{options:k,existingTags:l,tagType:S,selectedOptions:T,onChange:M})]})})]})})},Hs=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Us=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Gs=d(Ut)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Ys=d(Ce)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Ks=d(me)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Js=({feature:e,header:n})=>{const{tags:a,refetch:s}=ln(e.name),{deleteTagFromFeature:o}=Le(),[i,c]=f.useState(!1),[l,p]=f.useState(!1),[u,g]=f.useState(),{setToastData:h,setToastApiError:S}=U(),{hasAccess:b}=f.useContext(it),C=b(pe,e.project),R=async()=>{if(u)try{await o(e.name,u.type,u.value),s(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){S(N(y))}};return r(Hs,{children:[n,t(Us,{children:a.map(y=>{const m=`${y.type}:${y.value}`;return t(Gs,{label:m,deleteIcon:t(aa,{titleAccess:"Remove"}),onDelete:C?()=>{p(!0),g(y)}:void 0},m)})}),t(E,{condition:C,show:r(_,{children:[t(E,{condition:a.length>0,show:t(Ys,{})}),t(Ks,{"data-loading":!0,variant:"outlined",startIcon:t(oa,{}),onClick:()=>c(!0),children:"Add new tag"})]})}),t(dn,{open:i,setOpen:c}),r(ae,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{p(!1),g(void 0)},onClick:()=>{p(!1),R(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",r("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},Qs=d("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),Xe=d("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}})),Xs=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=A("projectId"),s=A("featureId"),{feature:o}=V(a,s);return r(Qs,{children:[t(Ns,{header:r(Xe,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:i})=>i).length,")",t(sa,{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(Ce,{}),t($s,{header:t(Xe,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(Ce,{}),t(Js,{header:t(Xe,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},Zs=()=>{const{trackEvent:e}=_e(),{value:n,setValue:a}=Nt(),[s,o]=f.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:s,setHiddenEnvironments:c=>{a(l=>{const p=new Set(l.hiddenEnvironments);return p.has(c)?(p.delete(c),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(p.add(c),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(p),{...n,hiddenEnvironments:p}})}}},er=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),tr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),nr=()=>{const e=re(),n=A("projectId"),a=A("featureId"),s=Vt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=Zs(),c=()=>e(s);return Gt(a),r(er,{children:[r("div",{children:[t(ho,{}),t(Xs,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(tr,{children:t(Fs,{})}),r(Yt,{children:[t(ne,{path:"strategies/create",element:t(tt,{label:"Create feature strategy",onClose:c,open:!0,children:t(Za,{})})}),t(ne,{path:"strategies/edit",element:t(tt,{label:"Edit feature strategy",onClose:c,open:!0,children:t(ra,{})})})]})]})},ar=d("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})),or=d(Kt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),sr=d("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})),rr=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ir=d(ie)(({theme:e})=>({marginBottom:e.spacing(2)})),cr=d(ie)(({theme:e})=>({marginTop:e.spacing(4)})),lr=d("div")({display:"flex",flexDirection:"column"}),dr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),$t=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ur=d(Ce)(({theme:e})=>({margin:e.spacing(4,0)})),pr=d(ia)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),gr=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),hr=d(me)(({theme:e})=>({marginLeft:e.spacing(3)})),fr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const c=A("projectId"),l=A("featureId"),{uiConfig:p}=Jt(),{context:u}=ca(),{defaultStickiness:g,loading:h}=la(c),{isChangeRequestConfigured:S}=se(c),{data:b}=fe(c),{changeRequestInReviewOrApproved:C,alert:R}=ga(b),y=(e==null?void 0:e.variants)||[],[m,T]=f.useState([]),[F,$]=f.useState();f.useEffect(()=>{h||T(y.length?y.map(x=>({...x,isValid:!0,new:!1,id:ze()})):[{name:"",weightType:gt.VARIABLE,weight:0,overrides:[],stickiness:(m==null?void 0:m.length)>0?m[0].stickiness:g,new:!0,isValid:!1,id:ze()}])},[n,h]);const j=(x,H)=>{T(le=>ht(le.map(Ie=>Ie.id===H?x:Ie),1e3))},k=()=>{const x=ze();T(H=>[...H,{name:"",weightType:gt.VARIABLE,weight:0,overrides:[],stickiness:(H==null?void 0:H.length)>0?H[0].stickiness:g,new:!0,isValid:!1,id:x}]),$(x)};f.useEffect(()=>{if(F){const x=document.getElementById(`variant-name-input-${F}`);x==null||x.scrollIntoView({behavior:"smooth",block:"center"}),x==null||x.focus({preventScroll:!0}),$(void 0)}},[F]);const P=m.map(({new:x,isValid:H,id:le,...Ie})=>Ie),B=s(y,P),G=o(P),K=async x=>{x.preventDefault(),i(P)},te=()=>D?`curl --location --request POST '${p.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(G,void 0,2)}'`:`curl --location --request PATCH '${p.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)}'`,ce=m.every(({isValid:x})=>x),w=C((e==null?void 0:e.name)||""),M=w?"Add to existing change request":"Add change to draft",D=S((e==null?void 0:e.name)||""),v=f.useMemo(()=>{var x;return h?"":((x=P[0])==null?void 0:x.stickiness)||g},[h,g,JSON.stringify(P[0]??{})]),I=f.useMemo(()=>["default",...u.filter(x=>x.stickiness).map(x=>x.name)],[u]),O=I.map(x=>({key:x,label:x}));I.includes(v)||O.push({key:v,label:v});const W=async x=>{T(H=>H.map(le=>({...le,stickiness:x})))},L=x=>{W(x)},[z,Ae]=f.useState();f.useEffect(()=>{Ae(void 0),B.error&&Ae(B.error)},[B.error]);const Re=()=>{W(g),a(!1)};return h||v===""?t(da,{}):t(tt,{open:n,onClose:Re,label:"",children:r(ua,{modal:!0,title:"",description:"Variants allows you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:te,loading:!n,children:[r(ar,{children:[r("div",{children:[t(or,{deprecated:!(e!=null&&e.enabled)}),t(sr,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(oe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:k,variant:"outlined",permission:de,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),r(rr,{onSubmit:K,children:[t(E,{condition:w,show:R,elseShow:t(E,{condition:!!D,show:r(ir,{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(lr,{children:m.map(x=>t(pa,{variant:x,variants:m,updateVariant:H=>j(H,x.id),removeVariant:()=>T(H=>ht(H.filter(le=>le.id!==x.id),1e3)),error:B.error},x.id))}),t(oe,{onClick:k,variant:"outlined",permission:de,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(ur,{}),t(E,{condition:m.length>0,show:r(_,{children:[t(dr,{children:t("p",{children:"Stickiness"})}),r($t,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(dt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(pr,{value:v,label:"",editable:!0,onChange:x=>L(x.target.value)})})]}),elseShow:t($t,{children:"This environment has no variants. Get started by adding a variant."})}),r(cr,{severity:"error",hidden:!z,children:[t("strong",{children:"Error: "}),z]}),r(gr,{children:[t(me,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ce,children:D?M:"Save variants"}),t(hr,{onClick:Re,children:"Cancel"})]})]})]})})},mr=d("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),yr=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Sr=d(Kt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),br=d("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})),Cr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),vr=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),Tr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),wr=({environment:e,searchValue:n,children:a})=>{var i;const s=e.variants??[],o=((i=s[0])==null?void 0:i.stickiness)||"default";return r(mr,{children:[r(yr,{children:[r("div",{children:[t(Sr,{deprecated:!e.enabled}),t(br,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:s.length>0,show:r(_,{children:[t(vr,{children:t(ha,{variants:s,searchValue:n})}),t(E,{condition:s.length>1,show:r(_,{children:[r(Tr,{children:[t("p",{children:"Stickiness:"}),t(be,{children:o})]}),r(Cr,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(dt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},xr=d(Se)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Er=({environment:e,permission:n,projectId:a,environmentId:s,onCopyVariantsFrom:o,otherEnvsWithVariants:i})=>{const[c,l]=f.useState(null),p=!!c,u=e.variants??[];return t(E,{condition:i.length>0&&u.length===0,show:r(_,{children:[t(oe,{onClick:g=>{l(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":p?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":p?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:s,children:"Copy variants from"}),t(Ee,{anchorEl:c,open:p,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(g=>t(he,{onClick:()=>o(g,e),children:t(xr,{children:`Copy from ${g.name}`})},g.name))})]})})},Ar=({permission:e,projectId:n,environment:a,checked:s,onClick:o,...i})=>{const c=et(e,n,a);return r(he,{disabled:!c,onClick:o,...i,children:[t(fa,{checked:s}),a]})},Rr=d(Ee)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Ir=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),Fr=d(me)(({theme:e})=>({marginTop:e.spacing(2)})),Dr=({current:e,environments:n,permission:a,projectId:s,onSubmit:o})=>{var R;const[i,c]=f.useState(null),l=!!i,[p,u]=f.useState([]),g=y=>{u(m=>[...m,y])},h=y=>{u(m=>m.filter(({name:T})=>T!==y.name))},S=y=>{p.includes(y)?h(y):g(y)},b=()=>{u([]),c(null)},C=((R=n.find(y=>y.name===e))==null?void 0:R.variants)??[];return t(E,{condition:C.length>0&&n.length>1,show:r(_,{children:[t(me,{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:"Push to environment"}),r(Rr,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(Ar,{projectId:s,permission:a,environment:y.name,checked:p.includes(y),onClick:()=>S(y)},y.name)),r(Ir,{children:[t(Ce,{}),r(Fr,{variant:"outlined",onClick:()=>{o(p),b()},disabled:p.length===0,children:["Push to selected (",p.length,")"]})]})]})]})})},kr=d(ie)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),$r=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Pr=()=>{const{setToastData:e,setToastApiError:n}=U(),a=zt(),s=Oe(a.breakpoints.down("md")),o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l,loading:p}=V(o,i),{patchFeatureEnvironmentVariants:u,overrideVariantsInEnvironments:g}=Le(),{refetch:h}=fe(o),{addChange:S}=Me(),{isChangeRequestConfigured:b}=se(o),[C,R]=f.useState(""),[y,m]=f.useState(),[T,F]=f.useState(!1),$=f.useMemo(()=>{var w;return((w=c==null?void 0:c.environments)==null?void 0:w.map(M=>({...M,crEnabled:b(M.name)})))||[]},[c.environments]),j=(w,M)=>Sa(w,M),k=(w,M)=>{try{const D=ya(M,1e3);return{patch:j(w,D)}}catch(D){return{patch:[],error:N(D)}}},P=w=>({feature:i,action:"patchVariant",payload:{variants:w}}),B=async(w,M)=>{if(w.crEnabled)await S(o,w.name,P(M)),h();else{const D=w.variants??[],{patch:v,error:I}=k(D,M);if(v.length===0)return;if(I){e({type:"error",title:I});return}await u(o,i,w.name,v)}l()},G=async(w,M)=>{try{const D=M.filter(({crEnabled:L})=>L),v=M.filter(({crEnabled:L})=>!L);D.length&&await Promise.all(D.map(L=>S(o,L.name,P(w)))),v.length&&await g(o,i,w,v.map(({name:L})=>L)),h(),l();const I=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",O=D.length?`Variants push added to ${D.length===1?`${D[0].name} draft`:`${D.length} drafts`}`:"",W=`${I}${I&&O?". ":""}${O}`;e({title:W,type:"success"})}catch(D){n(N(D))}},K=w=>{m(w),F(!0)},te=async w=>{if(y)try{await B(y,w),F(!1),e({title:y.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(M){n(N(M))}},ce=async(w,M)=>{try{const D=w.variants??[];await B(M,D),e({title:M.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(D){n(N(D))}};return r(ut,{isLoading:p,header:t(ma,{title:"Variants",actions:t(E,{condition:!s,show:t(_,{children:t(ft,{initialValue:C,onChange:R})})}),children:t(E,{condition:s,show:t(ft,{initialValue:C,onChange:R})})}),children:[r(kr,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(w=>{var D;const M=$.filter(({name:v,variants:I})=>v!==w.name&&(I==null?void 0:I.length));return t(wr,{environment:w,searchValue:C,children:r($r,{children:[t(Dr,{current:w.name,environments:$,permission:de,projectId:o,onSubmit:v=>G(w.variants??[],v)}),t(Er,{environment:w,permission:de,projectId:o,environmentId:w.name,onCopyVariantsFrom:ce,otherEnvsWithVariants:M}),t(E,{condition:!!((D=w.variants)!=null&&D.length),show:t(Z,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>K(w),permission:de,projectId:o,environmentId:w.name,tooltipProps:{title:"Edit variants"},children:t(ye,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>K(w),variant:"outlined",permission:de,projectId:o,environmentId:w.name,children:"Add variant"})})]})},w.name)}),t(fr,{environment:y,open:T,setOpen:F,getApiPayload:k,getCrPayload:P,onConfirm:te})]})},Br=Te("api/admin/client-metrics/features"),un=(e,n)=>{const a=Te(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:s,error:o}=ot(a,()=>Mr(a)),i=f.useCallback(()=>{st(Br).catch(console.warn)},[]);return{featureMetrics:s==null?void 0:s.data,loading:!o&&!s,refetchFeatureMetrics:i,error:o}},Mr=e=>fetch(e).then(Be("Features")).then(n=>n.json()).then(),Or=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),ve=48,_r=({hoursBack:e,setHoursBack:n})=>{const a=s=>{n(Lr(s))};return r("div",{children:[t(Or,{children:"Period"}),t(ba,{name:"feature-metrics-period",id:"feature-metrics-period",options:jr,value:String(e),onChange:a,fullWidth:!0})]})},Lr=e=>{switch(e){case"1":return 1;case"24":return 24;default:return ve}},jr=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${ve}`,label:`Last ${ve} hours`}],Vr=({value:e})=>{const{locationSettings:n}=qt(),a=e?e instanceof Date?mt(e,n.locale):mt(Ht(e),n.locale):void 0;return t(Qt,{lineClamp:1,children:a})},zr=({metrics:e,tableSectionId:n})=>{const a=Oe(Ca.breakpoints.down("md")),s=f.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:i,headerGroups:c,rows:l,prepareRow:p,setHiddenColumns:u}=We.useTable({initialState:s,columns:Pt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Qt}},We.useGlobalFilter,We.useSortBy);return va([{condition:a,columns:["appName","environment"]}],u,Pt),e.length===0?null:r(Ta,{...o(),rowHeight:"standard",id:n,children:[t(wa,{headerGroups:c}),t(xa,{...i(),children:l.map(g=>(p(g),t(Ea,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Aa,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Pt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ra,{icon:t(so,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Vr,{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"}],Wr=({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(cn,{...n,totalYes:a,totalNo:s})},Nr=({metrics:e,hoursBack:n})=>{const a=yt(),s=yt();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(qr,{metrics:e,hoursBack:n,statsSectionId:a})}),t(J,{mt:4,children:t(Wr,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(J,{mt:4,children:t(zr,{metrics:e,tableSectionId:s})})]})},qr=Ia.lazy(()=>import("./FeatureMetricsChart-839cdf1e.js")),at=e=>{const{search:n}=window.location,a=re(),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]},Hr=e=>{const[n,a]=at(e),s=f.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,s]},Ur=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Gr=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Yr=d("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}})),Bt=({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(Ur,{children:e}),t(Gr,{children:i.map(c=>t(Yr,{children:t(Ut,{label:c,onClick:o(c),"aria-pressed":c===a,sx:Fa})},c))})]})},Kr=()=>{const e=A("projectId"),n=A("featureId"),a=Jr(e,n),s=Qr(n);Gt("Metrics");const[o=ve,i]=Hr("hoursBack"),{featureMetrics:c}=un(n,o),[l,p]=f.useState(c);f.useEffect(()=>{c&&p(c)},[c]);const u=Array.from(a)[0],g=Array.from(s)[0],[h=u,S]=at("environment"),[b=g,C]=at("application"),R=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===h).filter(y=>y.appName===b),[l,h,b]);return R?r(ut,{children:[r(ee,{container:!0,component:"header",spacing:2,children:[t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(Bt,{title:"Environments",values:a,value:h,setValue:S})})}),t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:s.size>0,show:t(Bt,{title:"Applications",values:s,value:b,setValue:C})})}),t(ee,{item:!0,xs:12,md:2,children:t(_r,{hoursBack:o,setHoursBack:i})})]}),t(Nr,{metrics:R,hoursBack:o})]}):null},Jr=(e,n)=>{const{feature:a}=V(e,n),s=a.environments.map(o=>o.name);return new Set(s)},Qr=e=>{const{featureMetrics:n=[]}=un(e,ve),a=n.map(s=>s.appName);return new Set(a)},Xr=(e,n)=>{const a=new Set(e),s=new Set(n);return a.size!==s.size?!1:[...a].every(o=>s.has(o))},Mt=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Ot=d(ie)(({theme:e})=>({marginBottom:e.spacing(1)})),Zr=d(lt)({padding:0}),ei=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const c=A("projectId"),{project:l}=Xt(e),{isChangeRequestConfiguredInAnyEnv:p}=se(e),u=p(),g=f.useMemo(()=>Xr(o.environments.map(S=>S.name),l.environments.map(S=>S.environment)),[o,l]),h=i?i.length>0:!1;return t(E,{condition:g&&!h&&!u,show:t(ae,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:r(Mt,{children:[t(Ot,{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(ae,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:r(Mt,{children:[t(Ot,{severity:"warning",children:"Cannot proceed with the move"}),t(E,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(E,{condition:h,show:r(_,{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(Zr,{children:i==null?void 0:i.map(S=>t(ue,{children:r(Y,{to:`/projects/${c}/change-requests/${S.id}`,children:["View change request"," ",S.id]})},S.id))})]})}),t(E,{condition:u,show:r("p",{children:["You're not allowed to move the feature to project"," ",t(Y,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},ti=e=>fetch(e).then(Be("ChangeRequest")).then(n=>n.json()),ni=(e,n)=>{const{data:a,error:s,mutate:o}=Da([],Te(`api/admin/projects/${e}/change-requests/pending/${n}`),ti);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},ai=()=>{const{hasAccess:e}=f.useContext(it),n=A("projectId"),a=A("featureId"),{feature:s,refetchFeature:o}=V(n,a),[i,c]=f.useState(!1),{changeFeatureProject:l}=Le(),{setToastData:p,setToastApiError:u}=U(),[g,h]=f.useState(n),{projects:S}=ka(),b=re(),{changeRequests:C}=ni(n,a),R=async()=>{try{g&&(await l(n,a,g),o(),p({title:"Project changed",type:"success"}),c(!1),b(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(m){u(N(m))}},y=f.useMemo(()=>S.map(m=>m.id).filter(m=>e(St,m)),[S,e]);return y.length===0?null:r(_,{children:[t($a,{value:g,onChange:h,label:"Project",filter:m=>y.includes(m),enabled:!0}),t(oe,{permission:St,onClick:()=>c(!0),disabled:g===n,projectId:n,children:"Save"}),t(ei,{changeRequests:C,projectId:g,open:i,feature:s,onClose:()=>c(!1),onClick:R})]})},oi=d("div")({display:"flex",alignItems:"center"}),si=d(q)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),ri=({projectId:e,featureId:n})=>{var i;const{feature:a}=V(e,n),s=re();return r(_,{children:[r(oi,{children:[t(si,{children:"Feature information"}),t(Z,{permission:pe,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(ye,{})})]}),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"})]})]})},ke="metadata",Ze="project",ii=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ci=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),li=()=>{const e=A("projectId"),n=A("featureId"),[a,s]=f.useState(ke),{uiConfig:o}=Jt();return t(ut,{header:"Settings",sx:{padding:0},children:r(J,{sx:{display:"flex"},children:[t(ii,{children:r(lt,{children:[t(ue,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(ke),selected:a===ke,children:"Metadata"},0),t(ue,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ze),selected:a===Ze,hidden:!o.flags.P,children:"Project"},1)]})}),r(ci,{children:[t(E,{condition:a===ke,show:t(ri,{projectId:e,featureId:n})}),t(E,{condition:a===Ze&&o.flags.P,show:t(ai,{})})]})]})})},di=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(be,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),_t=d("strong")({wordBreak:"break-all"}),ui=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:a}=Pa(),s=Ba(e,{name:n});return a?a.some(i=>i.name===n)?r("p",{children:["The feature ",t(_t,{children:n})," has been archived. You can find it on the"," ",t(Y,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):r("p",{children:["The feature ",t(_t,{children:n})," does not exist. Would you like to"," ",t(Y,{to:s,children:"create it"}),"?"]}):null},pi=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),gi=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),hi=d("div")({display:"flex",alignItems:"center"}),fi=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),mi=d("div")({flexShrink:0,display:"flex"}),yi=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Si=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),bi=d(Ma)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),wi=()=>{const e=A("projectId"),n=A("featureId"),{refetch:a}=Xt(e),{favorite:s,unfavorite:o}=Oa(),{refetchFeature:i}=V(e,n),[c,l]=f.useState(!1),[p,u]=f.useState(!1),[g,h]=f.useState(!1),S=Oe("(max-width:500px)"),{feature:b,loading:C,error:R,status:y}=V(e,n),m=re(),{pathname:T}=_a(),F=La(C),$=`/projects/${e}/features/${n}`,j=[{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"}],k=j.find(B=>B.path===T)??j[0],P=async()=>{b!=null&&b.favorite?await o(e,b.name):await s(e,b.name),i()};return y===404?t(ui,{}):R!==void 0?t("div",{ref:F}):r("div",{ref:F,children:[r(pi,{children:[r(gi,{children:[r(hi,{children:[t(ja,{onClick:P,isFavorite:b==null?void 0:b.favorite}),r(fi,{"data-loading":!0,children:[b.name," "]}),t(E,{condition:!S,show:t(di,{stale:b==null?void 0:b.stale})})]}),r(mi,{children:[t(Z,{permission:Va,projectId:e,"data-loading":!0,component:Y,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(za,{})}),t(Z,{permission:Wa,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(oo,{})}),t(Z,{onClick:()=>h(!0),permission:pe,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(eo,{})}),t(Z,{onClick:()=>l(!0),permission:pe,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Na,{})})]})]}),t(yi,{}),t(Si,{children:t(qa,{value:k.path,indicatorColor:"primary",textColor:"primary",children:j.map(B=>t(bi,{label:B.title,value:B.path,onClick:()=>m(B.path),"data-testid":`TAB-${B.title}`},B.title))})})]}),r(Yt,{children:[t(ne,{path:"metrics",element:t(Kr,{})}),t(ne,{path:"logs",element:t(io,{})}),t(ne,{path:"variants",element:t(Pr,{})}),t(ne,{path:"settings",element:t(li,{})}),t(ne,{path:"*",element:t(nr,{})})]}),t(to,{isOpen:p,onConfirm:()=>{a(),m(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureIds:[n]}),t(no,{isStale:b.stale,isOpen:g,onClose:()=>{h(!1),i()},featureId:n,projectId:e}),t(dn,{open:c,setOpen:l})]})};export{wi as default};
|
|
7
|
+
--data-raw '${JSON.stringify(B.patch,void 0,2)}'`,ce=m.every(({isValid:x})=>x),w=C((e==null?void 0:e.name)||""),M=w?"Add to existing change request":"Add change to draft",D=S((e==null?void 0:e.name)||""),v=f.useMemo(()=>{var x;return h?"":((x=P[0])==null?void 0:x.stickiness)||g},[h,g,JSON.stringify(P[0]??{})]),I=f.useMemo(()=>["default",...u.filter(x=>x.stickiness).map(x=>x.name)],[u]),O=I.map(x=>({key:x,label:x}));I.includes(v)||O.push({key:v,label:v});const W=async x=>{T(H=>H.map(le=>({...le,stickiness:x})))},L=x=>{W(x)},[z,Ae]=f.useState();f.useEffect(()=>{Ae(void 0),B.error&&Ae(B.error)},[B.error]);const Re=()=>{W(g),a(!1)};return h||v===""?t(da,{}):t(tt,{open:n,onClose:Re,label:"",children:r(ua,{modal:!0,title:"",description:"Variants allows you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:te,loading:!n,children:[r(ar,{children:[r("div",{children:[t(or,{deprecated:!(e!=null&&e.enabled)}),t(sr,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(oe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:k,variant:"outlined",permission:de,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),r(rr,{onSubmit:K,children:[t(E,{condition:w,show:R,elseShow:t(E,{condition:!!D,show:r(ir,{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(lr,{children:m.map(x=>t(pa,{variant:x,variants:m,updateVariant:H=>j(H,x.id),removeVariant:()=>T(H=>ht(H.filter(le=>le.id!==x.id),1e3)),error:B.error},x.id))}),t(oe,{onClick:k,variant:"outlined",permission:de,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(ur,{}),t(E,{condition:m.length>0,show:r(_,{children:[t(dr,{children:t("p",{children:"Stickiness"})}),r($t,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(dt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(pr,{value:v,label:"",editable:!0,onChange:x=>L(x.target.value)})})]}),elseShow:t($t,{children:"This environment has no variants. Get started by adding a variant."})}),r(cr,{severity:"error",hidden:!z,children:[t("strong",{children:"Error: "}),z]}),r(gr,{children:[t(me,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ce,children:D?M:"Save variants"}),t(hr,{onClick:Re,children:"Cancel"})]})]})]})})},mr=d("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),yr=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Sr=d(Kt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),br=d("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})),Cr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),vr=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),Tr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),wr=({environment:e,searchValue:n,children:a})=>{var i;const s=e.variants??[],o=((i=s[0])==null?void 0:i.stickiness)||"default";return r(mr,{children:[r(yr,{children:[r("div",{children:[t(Sr,{deprecated:!e.enabled}),t(br,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:s.length>0,show:r(_,{children:[t(vr,{children:t(ha,{variants:s,searchValue:n})}),t(E,{condition:s.length>1,show:r(_,{children:[r(Tr,{children:[t("p",{children:"Stickiness:"}),t(be,{children:o})]}),r(Cr,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(dt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},xr=d(Se)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Er=({environment:e,permission:n,projectId:a,environmentId:s,onCopyVariantsFrom:o,otherEnvsWithVariants:i})=>{const[c,l]=f.useState(null),p=!!c,u=e.variants??[];return t(E,{condition:i.length>0&&u.length===0,show:r(_,{children:[t(oe,{onClick:g=>{l(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":p?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":p?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:s,children:"Copy variants from"}),t(Ee,{anchorEl:c,open:p,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(g=>t(he,{onClick:()=>o(g,e),children:t(xr,{children:`Copy from ${g.name}`})},g.name))})]})})},Ar=({permission:e,projectId:n,environment:a,checked:s,onClick:o,...i})=>{const c=et(e,n,a);return r(he,{disabled:!c,onClick:o,...i,children:[t(fa,{checked:s}),a]})},Rr=d(Ee)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Ir=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),Fr=d(me)(({theme:e})=>({marginTop:e.spacing(2)})),Dr=({current:e,environments:n,permission:a,projectId:s,onSubmit:o})=>{var R;const[i,c]=f.useState(null),l=!!i,[p,u]=f.useState([]),g=y=>{u(m=>[...m,y])},h=y=>{u(m=>m.filter(({name:T})=>T!==y.name))},S=y=>{p.includes(y)?h(y):g(y)},b=()=>{u([]),c(null)},C=((R=n.find(y=>y.name===e))==null?void 0:R.variants)??[];return t(E,{condition:C.length>0&&n.length>1,show:r(_,{children:[t(me,{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:"Push to environment"}),r(Rr,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(Ar,{projectId:s,permission:a,environment:y.name,checked:p.includes(y),onClick:()=>S(y)},y.name)),r(Ir,{children:[t(Ce,{}),r(Fr,{variant:"outlined",onClick:()=>{o(p),b()},disabled:p.length===0,children:["Push to selected (",p.length,")"]})]})]})]})})},kr=d(ie)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),$r=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Pr=()=>{const{setToastData:e,setToastApiError:n}=U(),a=zt(),s=Oe(a.breakpoints.down("md")),o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l,loading:p}=V(o,i),{patchFeatureEnvironmentVariants:u,overrideVariantsInEnvironments:g}=Le(),{refetch:h}=fe(o),{addChange:S}=Me(),{isChangeRequestConfigured:b}=se(o),[C,R]=f.useState(""),[y,m]=f.useState(),[T,F]=f.useState(!1),$=f.useMemo(()=>{var w;return((w=c==null?void 0:c.environments)==null?void 0:w.map(M=>({...M,crEnabled:b(M.name)})))||[]},[c.environments]),j=(w,M)=>Sa(w,M),k=(w,M)=>{try{const D=ya(M,1e3);return{patch:j(w,D)}}catch(D){return{patch:[],error:N(D)}}},P=w=>({feature:i,action:"patchVariant",payload:{variants:w}}),B=async(w,M)=>{if(w.crEnabled)await S(o,w.name,P(M)),h();else{const D=w.variants??[],{patch:v,error:I}=k(D,M);if(v.length===0)return;if(I){e({type:"error",title:I});return}await u(o,i,w.name,v)}l()},G=async(w,M)=>{try{const D=M.filter(({crEnabled:L})=>L),v=M.filter(({crEnabled:L})=>!L);D.length&&await Promise.all(D.map(L=>S(o,L.name,P(w)))),v.length&&await g(o,i,w,v.map(({name:L})=>L)),h(),l();const I=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",O=D.length?`Variants push added to ${D.length===1?`${D[0].name} draft`:`${D.length} drafts`}`:"",W=`${I}${I&&O?". ":""}${O}`;e({title:W,type:"success"})}catch(D){n(N(D))}},K=w=>{m(w),F(!0)},te=async w=>{if(y)try{await B(y,w),F(!1),e({title:y.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(M){n(N(M))}},ce=async(w,M)=>{try{const D=w.variants??[];await B(M,D),e({title:M.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(D){n(N(D))}};return r(ut,{isLoading:p,header:t(ma,{title:"Variants",actions:t(E,{condition:!s,show:t(_,{children:t(ft,{initialValue:C,onChange:R})})}),children:t(E,{condition:s,show:t(ft,{initialValue:C,onChange:R})})}),children:[r(kr,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(w=>{var D;const M=$.filter(({name:v,variants:I})=>v!==w.name&&(I==null?void 0:I.length));return t(wr,{environment:w,searchValue:C,children:r($r,{children:[t(Dr,{current:w.name,environments:$,permission:de,projectId:o,onSubmit:v=>G(w.variants??[],v)}),t(Er,{environment:w,permission:de,projectId:o,environmentId:w.name,onCopyVariantsFrom:ce,otherEnvsWithVariants:M}),t(E,{condition:!!((D=w.variants)!=null&&D.length),show:t(Z,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>K(w),permission:de,projectId:o,environmentId:w.name,tooltipProps:{title:"Edit variants"},children:t(ye,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>K(w),variant:"outlined",permission:de,projectId:o,environmentId:w.name,children:"Add variant"})})]})},w.name)}),t(fr,{environment:y,open:T,setOpen:F,getApiPayload:k,getCrPayload:P,onConfirm:te})]})},Br=Te("api/admin/client-metrics/features"),un=(e,n)=>{const a=Te(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:s,error:o}=ot(a,()=>Mr(a)),i=f.useCallback(()=>{st(Br).catch(console.warn)},[]);return{featureMetrics:s==null?void 0:s.data,loading:!o&&!s,refetchFeatureMetrics:i,error:o}},Mr=e=>fetch(e).then(Be("Features")).then(n=>n.json()).then(),Or=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),ve=48,_r=({hoursBack:e,setHoursBack:n})=>{const a=s=>{n(Lr(s))};return r("div",{children:[t(Or,{children:"Period"}),t(ba,{name:"feature-metrics-period",id:"feature-metrics-period",options:jr,value:String(e),onChange:a,fullWidth:!0})]})},Lr=e=>{switch(e){case"1":return 1;case"24":return 24;default:return ve}},jr=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${ve}`,label:`Last ${ve} hours`}],Vr=({value:e})=>{const{locationSettings:n}=qt(),a=e?e instanceof Date?mt(e,n.locale):mt(Ht(e),n.locale):void 0;return t(Qt,{lineClamp:1,children:a})},zr=({metrics:e,tableSectionId:n})=>{const a=Oe(Ca.breakpoints.down("md")),s=f.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:i,headerGroups:c,rows:l,prepareRow:p,setHiddenColumns:u}=We.useTable({initialState:s,columns:Pt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Qt}},We.useGlobalFilter,We.useSortBy);return va([{condition:a,columns:["appName","environment"]}],u,Pt),e.length===0?null:r(Ta,{...o(),rowHeight:"standard",id:n,children:[t(wa,{headerGroups:c}),t(xa,{...i(),children:l.map(g=>(p(g),t(Ea,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Aa,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Pt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ra,{icon:t(so,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Vr,{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"}],Wr=({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(cn,{...n,totalYes:a,totalNo:s})},Nr=({metrics:e,hoursBack:n})=>{const a=yt(),s=yt();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(qr,{metrics:e,hoursBack:n,statsSectionId:a})}),t(J,{mt:4,children:t(Wr,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(J,{mt:4,children:t(zr,{metrics:e,tableSectionId:s})})]})},qr=Ia.lazy(()=>import("./FeatureMetricsChart-81da0ce4.js")),at=e=>{const{search:n}=window.location,a=re(),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]},Hr=e=>{const[n,a]=at(e),s=f.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,s]},Ur=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Gr=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Yr=d("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}})),Bt=({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(Ur,{children:e}),t(Gr,{children:i.map(c=>t(Yr,{children:t(Ut,{label:c,onClick:o(c),"aria-pressed":c===a,sx:Fa})},c))})]})},Kr=()=>{const e=A("projectId"),n=A("featureId"),a=Jr(e,n),s=Qr(n);Gt("Metrics");const[o=ve,i]=Hr("hoursBack"),{featureMetrics:c}=un(n,o),[l,p]=f.useState(c);f.useEffect(()=>{c&&p(c)},[c]);const u=Array.from(a)[0],g=Array.from(s)[0],[h=u,S]=at("environment"),[b=g,C]=at("application"),R=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===h).filter(y=>y.appName===b),[l,h,b]);return R?r(ut,{children:[r(ee,{container:!0,component:"header",spacing:2,children:[t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(Bt,{title:"Environments",values:a,value:h,setValue:S})})}),t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:s.size>0,show:t(Bt,{title:"Applications",values:s,value:b,setValue:C})})}),t(ee,{item:!0,xs:12,md:2,children:t(_r,{hoursBack:o,setHoursBack:i})})]}),t(Nr,{metrics:R,hoursBack:o})]}):null},Jr=(e,n)=>{const{feature:a}=V(e,n),s=a.environments.map(o=>o.name);return new Set(s)},Qr=e=>{const{featureMetrics:n=[]}=un(e,ve),a=n.map(s=>s.appName);return new Set(a)},Xr=(e,n)=>{const a=new Set(e),s=new Set(n);return a.size!==s.size?!1:[...a].every(o=>s.has(o))},Mt=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Ot=d(ie)(({theme:e})=>({marginBottom:e.spacing(1)})),Zr=d(lt)({padding:0}),ei=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const c=A("projectId"),{project:l}=Xt(e),{isChangeRequestConfiguredInAnyEnv:p}=se(e),u=p(),g=f.useMemo(()=>Xr(o.environments.map(S=>S.name),l.environments.map(S=>S.environment)),[o,l]),h=i?i.length>0:!1;return t(E,{condition:g&&!h&&!u,show:t(ae,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:r(Mt,{children:[t(Ot,{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(ae,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:r(Mt,{children:[t(Ot,{severity:"warning",children:"Cannot proceed with the move"}),t(E,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(E,{condition:h,show:r(_,{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(Zr,{children:i==null?void 0:i.map(S=>t(ue,{children:r(Y,{to:`/projects/${c}/change-requests/${S.id}`,children:["View change request"," ",S.id]})},S.id))})]})}),t(E,{condition:u,show:r("p",{children:["You're not allowed to move the feature to project"," ",t(Y,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},ti=e=>fetch(e).then(Be("ChangeRequest")).then(n=>n.json()),ni=(e,n)=>{const{data:a,error:s,mutate:o}=Da([],Te(`api/admin/projects/${e}/change-requests/pending/${n}`),ti);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},ai=()=>{const{hasAccess:e}=f.useContext(it),n=A("projectId"),a=A("featureId"),{feature:s,refetchFeature:o}=V(n,a),[i,c]=f.useState(!1),{changeFeatureProject:l}=Le(),{setToastData:p,setToastApiError:u}=U(),[g,h]=f.useState(n),{projects:S}=ka(),b=re(),{changeRequests:C}=ni(n,a),R=async()=>{try{g&&(await l(n,a,g),o(),p({title:"Project changed",type:"success"}),c(!1),b(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(m){u(N(m))}},y=f.useMemo(()=>S.map(m=>m.id).filter(m=>e(St,m)),[S,e]);return y.length===0?null:r(_,{children:[t($a,{value:g,onChange:h,label:"Project",filter:m=>y.includes(m),enabled:!0}),t(oe,{permission:St,onClick:()=>c(!0),disabled:g===n,projectId:n,children:"Save"}),t(ei,{changeRequests:C,projectId:g,open:i,feature:s,onClose:()=>c(!1),onClick:R})]})},oi=d("div")({display:"flex",alignItems:"center"}),si=d(q)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),ri=({projectId:e,featureId:n})=>{var i;const{feature:a}=V(e,n),s=re();return r(_,{children:[r(oi,{children:[t(si,{children:"Feature information"}),t(Z,{permission:pe,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(ye,{})})]}),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"})]})]})},ke="metadata",Ze="project",ii=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ci=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),li=()=>{const e=A("projectId"),n=A("featureId"),[a,s]=f.useState(ke),{uiConfig:o}=Jt();return t(ut,{header:"Settings",sx:{padding:0},children:r(J,{sx:{display:"flex"},children:[t(ii,{children:r(lt,{children:[t(ue,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(ke),selected:a===ke,children:"Metadata"},0),t(ue,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ze),selected:a===Ze,hidden:!o.flags.P,children:"Project"},1)]})}),r(ci,{children:[t(E,{condition:a===ke,show:t(ri,{projectId:e,featureId:n})}),t(E,{condition:a===Ze&&o.flags.P,show:t(ai,{})})]})]})})},di=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(be,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),_t=d("strong")({wordBreak:"break-all"}),ui=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:a}=Pa(),s=Ba(e,{name:n});return a?a.some(i=>i.name===n)?r("p",{children:["The feature ",t(_t,{children:n})," has been archived. You can find it on the"," ",t(Y,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):r("p",{children:["The feature ",t(_t,{children:n})," does not exist. Would you like to"," ",t(Y,{to:s,children:"create it"}),"?"]}):null},pi=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),gi=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),hi=d("div")({display:"flex",alignItems:"center"}),fi=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),mi=d("div")({flexShrink:0,display:"flex"}),yi=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Si=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),bi=d(Ma)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),wi=()=>{const e=A("projectId"),n=A("featureId"),{refetch:a}=Xt(e),{favorite:s,unfavorite:o}=Oa(),{refetchFeature:i}=V(e,n),[c,l]=f.useState(!1),[p,u]=f.useState(!1),[g,h]=f.useState(!1),S=Oe("(max-width:500px)"),{feature:b,loading:C,error:R,status:y}=V(e,n),m=re(),{pathname:T}=_a(),F=La(C),$=`/projects/${e}/features/${n}`,j=[{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"}],k=j.find(B=>B.path===T)??j[0],P=async()=>{b!=null&&b.favorite?await o(e,b.name):await s(e,b.name),i()};return y===404?t(ui,{}):R!==void 0?t("div",{ref:F}):r("div",{ref:F,children:[r(pi,{children:[r(gi,{children:[r(hi,{children:[t(ja,{onClick:P,isFavorite:b==null?void 0:b.favorite}),r(fi,{"data-loading":!0,children:[b.name," "]}),t(E,{condition:!S,show:t(di,{stale:b==null?void 0:b.stale})})]}),r(mi,{children:[t(Z,{permission:Va,projectId:e,"data-loading":!0,component:Y,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(za,{})}),t(Z,{permission:Wa,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(oo,{})}),t(Z,{onClick:()=>h(!0),permission:pe,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(eo,{})}),t(Z,{onClick:()=>l(!0),permission:pe,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Na,{})})]})]}),t(yi,{}),t(Si,{children:t(qa,{value:k.path,indicatorColor:"primary",textColor:"primary",children:j.map(B=>t(bi,{label:B.title,value:B.path,onClick:()=>m(B.path),"data-testid":`TAB-${B.title}`},B.title))})})]}),r(Yt,{children:[t(ne,{path:"metrics",element:t(Kr,{})}),t(ne,{path:"logs",element:t(io,{})}),t(ne,{path:"variants",element:t(Pr,{})}),t(ne,{path:"settings",element:t(li,{})}),t(ne,{path:"*",element:t(nr,{})})]}),t(to,{isOpen:p,onConfirm:()=>{a(),m(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureIds:[n]}),t(no,{isStale:b.stale,isOpen:g,onClose:()=>{h(!1),i()},featureId:n,projectId:e}),t(dn,{open:c,setOpen:l})]})};export{wi as default};
|