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