unleash-server 6.2.0 → 6.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/features/project/can-grant-project-role.d.ts +4 -0
- package/dist/lib/features/project/can-grant-project-role.d.ts.map +1 -0
- package/dist/lib/features/project/can-grant-project-role.js +17 -0
- package/dist/lib/features/project/can-grant-project-role.js.map +1 -0
- package/dist/lib/features/project/can-grant-project-role.test.d.ts +2 -0
- package/dist/lib/features/project/can-grant-project-role.test.d.ts.map +1 -0
- package/dist/lib/features/project/can-grant-project-role.test.js +111 -0
- package/dist/lib/features/project/can-grant-project-role.test.js.map +1 -0
- package/dist/lib/features/project/project-service.d.ts.map +1 -1
- package/dist/lib/features/project/project-service.e2e.test.js +31 -29
- package/dist/lib/features/project/project-service.e2e.test.js.map +1 -1
- package/dist/lib/features/project/project-service.js +13 -1
- package/dist/lib/features/project/project-service.js.map +1 -1
- package/dist/lib/features/project-environments/environments.d.ts.map +1 -1
- package/dist/lib/features/project-environments/environments.js +1 -1
- package/dist/lib/features/project-environments/environments.js.map +1 -1
- package/dist/lib/routes/admin-api/user/user.d.ts +1 -0
- package/dist/lib/routes/admin-api/user/user.d.ts.map +1 -1
- package/dist/lib/routes/admin-api/user/user.js +8 -1
- package/dist/lib/routes/admin-api/user/user.js.map +1 -1
- package/dist/lib/types/experimental.d.ts +1 -1
- package/dist/lib/types/experimental.d.ts.map +1 -1
- package/dist/lib/types/experimental.js +1 -0
- package/dist/lib/types/experimental.js.map +1 -1
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{AdvancedPlayground-CRj3J15M.js → AdvancedPlayground-CRdeeG3w.js} +1 -1
- package/frontend/build/static/{CreateProject-CoMWBmMC.js → CreateProject-8AyZj2dp.js} +1 -1
- package/frontend/build/static/{FeatureMetricsChart-CJrrWMue.js → FeatureMetricsChart-DEo4WxO1.js} +1 -1
- package/frontend/build/static/FeatureStaleDialog-CrsbH2rq.js +7 -0
- package/frontend/build/static/{FeatureViewLazyExport-CCemx_kk.js → FeatureViewLazyExport-BwY7TYmZ.js} +2 -2
- package/frontend/build/static/{LazyAdminExport-C8Z5ig95.js → LazyAdminExport-0g_UOhr3.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-Dooc4t2t.js → LazyProjectExport-C1eSkT3Z.js} +18 -18
- package/frontend/build/static/LineChartComponent-BLXX5chp.js +1 -0
- package/frontend/build/static/{NetworkOverview-DakM348r.js → NetworkOverview-DqGLVIJ6.js} +1 -1
- package/frontend/build/static/{NetworkTraffic-CfqRQOHm.js → NetworkTraffic-BWFLlaz7.js} +1 -1
- package/frontend/build/static/{NetworkTrafficUsage-BnIFfNNJ.js → NetworkTrafficUsage-BvoBumVR.js} +1 -1
- package/frontend/build/static/{ReactJSONEditor-z4lldZFR.js → ReactJSONEditor-Bvhd5heT.js} +1 -1
- package/frontend/build/static/{RoleCell-BLQYE7NO.js → RoleCell-DGcue0jn.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-0nEHrvdC.js → StrategyItemContainer-Das6_30A.js} +1 -1
- package/frontend/build/static/{index-DhEaCpkq.js → index-BsIpdLcw.js} +1 -1
- package/frontend/build/static/{index-C5Z6aehP.js → index-Cx91uh9W.js} +17 -17
- package/frontend/build/static/{unknownify-CLPkLMVA.js → unknownify-8qa4PVkQ.js} +1 -1
- package/frontend/build/static/{useApiTokens-DfEYjYPV.js → useApiTokens-5JgqgHim.js} +1 -1
- package/package.json +1 -1
- package/frontend/build/static/FeatureStaleDialog-Yc2Yc4V5.js +0 -7
- package/frontend/build/static/LineChartComponent-BxkVmXGQ.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aA as Ls,aB as Os,_ as It,aC as $n,a as re,aD as it,j as t,s as u,aE as Fn,aF as Be,r as x,aG as _s,b as ct,aH as Dt,aI as Oe,aJ as Ms,aK as k,aL as W,aM as In,L as ne,aN as be,aO as Pn,N as he,A as Bn,aP as zs,l as Ln,aQ as On,aR as _n,aS as Pt,u as Mn,h as G,an as Se,aT as Ee,aU as ve,e as ae,aV as Bt,aW as ce,B as Q,T as J,C,a5 as Vs,t as ue,w as Qe,aX as Lt,aY as zn,M as we,aZ as Me,a_ as ze,a$ as ke,b0 as Ns,b1 as Xe,b2 as qs,b3 as Te,b4 as Kt,b5 as Fe,b6 as Ws,b7 as qe,b8 as We,b9 as Vn,ba as Re,bb as Us,bc as Nn,bd as je,be as Ve,bf as qn,bg as Hs,bh as Wn,bi as Un,bj as Ys,bk as Ot,bl as Gs,bm as Hn,bn as Yn,bo as Gn,bp as Jn,bq as Kn,br as Qn,bs as Xn,bt as Zn,bu as Y,bv as ea,bw as ta,bx as Qt,by as Xt,bz as Ye,bA as sa,bB as gt,bC as na,bD as Zt,bE as aa,bF as es,bG as oa,bH as ra,bI as ia,bJ as ca,bK as Ze,bL as Ue,bM as $e,bN as la,bO as da,bP as et,bQ as Js,bR as Ks,bS as _t,bT as ua,bU as kt,bV as pa,bW as ga,bX as ha,bY as fa,bZ as xa,b_ as ya,b$ as ma,c0 as ja,c1 as ba,c2 as Sa,c3 as ts,c4 as Qs,c5 as va,ag as tt,H as Ne,Q as Ca,c6 as Mt,i as Ie,c7 as ss,c8 as wa,c9 as Ta,ca as Ea,cb as Ra,cc as Aa,cd as Da,ce as Xs,cf as ka,cg as $a,ch as Fa,ci as Ia,cj as Pa,ck as Ba,cl as La,Y as zt,cm as Zs,a1 as Oa,cn as Vt,co as _e,cp as en,cq as _a,cr as Ma,cs as Ce,ct as za,cu as Va,a0 as Na,am as qa,cv as Wa,cw as Ua,cx as Ha,cy as Ya,cz as Ga,cA as Ja,cB as Ka,cC as Qa,cD as Nt,cE as Xa,cF as lt,cG as Za,X as tn,D as dt,cH as eo,cI as to,cJ as so,cK as no,cL as sn,cM as ao,cN as nn,cO as Ae,cP as $t,cQ as oo,cR as an,cS as ro,cT as io,f as co,cU as lo,cV as ht,cW as ns,az as uo,cX as Le,cY as as,cZ as po,c_ as go,c$ as ho,ax as qt,ay as fo,as as os,d0 as xo,d1 as yo,d2 as mo,d3 as rs,af as at,x as jo,y as bo,d4 as So,a7 as ft,aj as vo,a9 as Co,aa as wo,ab as To,ac as Eo,ad as Ro,ae as Ao,d5 as Do,d6 as is,d7 as ko,d8 as $o,d9 as xt,da as Fo,db as Io,dc as Po,q as on,dd as Bo,de as cs,df as Lo,dg as Oo,dh as _o,di as Mo,dj as zo,dk as Vo,dl as No,ap as qo,dm as Wo,d as Uo,dn as Ho,dp as Yo,dq as Go,dr as Jo,ds as Ko,dt as Qo}from"./index-C5Z6aehP.js";import{u as Xo,a as Zo,F as rn,M as er,C as cn,b as tr,c as sr,d as nr,V as ar,e as or,f as rr,T as ir,g as cr,h as lr,i as dr,j as ur,k as pr}from"./FeatureStaleDialog-Yc2Yc4V5.js";import{S as gr}from"./StrategyItemContainer-0nEHrvdC.js";function hr(e){return Ls("MuiPagination",e)}Os("MuiPagination",["root","ul","outlined","text"]);const fr=["boundaryCount","componentName","count","defaultPage","disabled","hideNextButton","hidePrevButton","onChange","page","showFirstButton","showLastButton","siblingCount"];function xr(e={}){const{boundaryCount:s=1,componentName:n="usePagination",count:a=1,defaultPage:o=1,disabled:r=!1,hideNextButton:i=!1,hidePrevButton:c=!1,onChange:l,page:d,showFirstButton:g=!1,showLastButton:f=!1,siblingCount:m=1}=e,y=It(e,fr),[j,S]=$n({controlled:d,default:o,name:n,state:"page"}),h=(E,_)=>{d||S(_),l&&l(E,_)},p=(E,_)=>{const X=_-E+1;return Array.from({length:X},(te,b)=>E+b)},w=p(1,Math.min(s,a)),I=p(Math.max(a-s+1,s+1),a),B=Math.max(Math.min(j-m,a-s-m*2-1),s+2),O=Math.min(Math.max(j+m,s+m*2+2),I.length>0?I[0]-2:a-1),$=[...g?["first"]:[],...c?[]:["previous"],...w,...B>s+2?["start-ellipsis"]:s+1<a-s?[s+1]:[],...p(B,O),...O<a-s-1?["end-ellipsis"]:a-s>s?[a-s]:[],...I,...i?[]:["next"],...f?["last"]:[]],P=E=>{switch(E){case"first":return 1;case"previous":return j-1;case"next":return j+1;case"last":return a;default:return null}},R=$.map(E=>typeof E=="number"?{onClick:_=>{h(_,E)},type:"page",page:E,selected:E===j,disabled:r,"aria-current":E===j?"true":void 0}:{onClick:_=>{h(_,P(E))},type:E,page:P(E),selected:!1,disabled:r||E.indexOf("ellipsis")===-1&&(E==="next"||E==="last"?j>=a:j<=1)});return re({items:R},y)}function yr(e){return Ls("MuiPaginationItem",e)}const de=Os("MuiPaginationItem",["root","page","sizeSmall","sizeLarge","text","textPrimary","textSecondary","outlined","outlinedPrimary","outlinedSecondary","rounded","ellipsis","firstLast","previousNext","focusVisible","disabled","selected","icon"]),ls=it(t.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"}),"FirstPage"),ds=it(t.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"}),"LastPage"),us=it(t.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"}),"NavigateBefore"),ps=it(t.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}),"NavigateNext"),mr=["className","color","component","components","disabled","page","selected","shape","size","slots","type","variant"],ln=(e,s)=>{const{ownerState:n}=e;return[s.root,s[n.variant],s[`size${Oe(n.size)}`],n.variant==="text"&&s[`text${Oe(n.color)}`],n.variant==="outlined"&&s[`outlined${Oe(n.color)}`],n.shape==="rounded"&&s.rounded,n.type==="page"&&s.page,(n.type==="start-ellipsis"||n.type==="end-ellipsis")&&s.ellipsis,(n.type==="previous"||n.type==="next")&&s.previousNext,(n.type==="first"||n.type==="last")&&s.firstLast]},jr=e=>{const{classes:s,color:n,disabled:a,selected:o,size:r,shape:i,type:c,variant:l}=e,d={root:["root",`size${Oe(r)}`,l,i,n!=="standard"&&`${l}${Oe(n)}`,a&&"disabled",o&&"selected",{page:"page",first:"firstLast",last:"firstLast","start-ellipsis":"ellipsis","end-ellipsis":"ellipsis",previous:"previousNext",next:"previousNext"}[c]],icon:["icon"]};return Ms(d,yr,s)},br=u("div",{name:"MuiPaginationItem",slot:"Root",overridesResolver:ln})(({theme:e,ownerState:s})=>re({},e.typography.body2,{borderRadius:32/2,textAlign:"center",boxSizing:"border-box",minWidth:32,padding:"0 6px",margin:"0 3px",color:(e.vars||e).palette.text.primary,height:"auto",[`&.${de.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity}},s.size==="small"&&{minWidth:26,borderRadius:26/2,margin:"0 1px",padding:"0 4px"},s.size==="large"&&{minWidth:40,borderRadius:40/2,padding:"0 10px",fontSize:e.typography.pxToRem(15)})),Sr=u(Fn,{name:"MuiPaginationItem",slot:"Root",overridesResolver:ln})(({theme:e,ownerState:s})=>re({},e.typography.body2,{borderRadius:32/2,textAlign:"center",boxSizing:"border-box",minWidth:32,height:32,padding:"0 6px",margin:"0 3px",color:(e.vars||e).palette.text.primary,[`&.${de.focusVisible}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${de.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity},transition:e.transitions.create(["color","background-color"],{duration:e.transitions.duration.short}),"&:hover":{backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${de.selected}`]:{backgroundColor:(e.vars||e).palette.action.selected,"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette.action.selectedChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:Be(e.palette.action.selected,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:(e.vars||e).palette.action.selected}},[`&.${de.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.action.selectedChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette.action.selected,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)},[`&.${de.disabled}`]:{opacity:1,color:(e.vars||e).palette.action.disabled,backgroundColor:(e.vars||e).palette.action.selected}}},s.size==="small"&&{minWidth:26,height:26,borderRadius:26/2,margin:"0 1px",padding:"0 4px"},s.size==="large"&&{minWidth:40,height:40,borderRadius:40/2,padding:"0 10px",fontSize:e.typography.pxToRem(15)},s.shape==="rounded"&&{borderRadius:(e.vars||e).shape.borderRadius}),({theme:e,ownerState:s})=>re({},s.variant==="text"&&{[`&.${de.selected}`]:re({},s.color!=="standard"&&{color:(e.vars||e).palette[s.color].contrastText,backgroundColor:(e.vars||e).palette[s.color].main,"&:hover":{backgroundColor:(e.vars||e).palette[s.color].dark,"@media (hover: none)":{backgroundColor:(e.vars||e).palette[s.color].main}},[`&.${de.focusVisible}`]:{backgroundColor:(e.vars||e).palette[s.color].dark}},{[`&.${de.disabled}`]:{color:(e.vars||e).palette.action.disabled}})},s.variant==="outlined"&&{border:e.vars?`1px solid rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:`1px solid ${e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)"}`,[`&.${de.selected}`]:re({},s.color!=="standard"&&{color:(e.vars||e).palette[s.color].main,border:`1px solid ${e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / 0.5)`:Be(e.palette[s.color].main,.5)}`,backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / ${e.vars.palette.action.activatedOpacity})`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity),"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / calc(${e.vars.palette.action.activatedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity+e.palette.action.focusOpacity),"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${de.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / calc(${e.vars.palette.action.activatedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity+e.palette.action.focusOpacity)}},{[`&.${de.disabled}`]:{borderColor:(e.vars||e).palette.action.disabledBackground,color:(e.vars||e).palette.action.disabled}})})),vr=u("div",{name:"MuiPaginationItem",slot:"Icon",overridesResolver:(e,s)=>s.icon})(({theme:e,ownerState:s})=>re({fontSize:e.typography.pxToRem(20),margin:"0 -8px"},s.size==="small"&&{fontSize:e.typography.pxToRem(18)},s.size==="large"&&{fontSize:e.typography.pxToRem(22)})),Cr=x.forwardRef(function(s,n){const a=_s({props:s,name:"MuiPaginationItem"}),{className:o,color:r="standard",component:i,components:c={},disabled:l=!1,page:d,selected:g=!1,shape:f="circular",size:m="medium",slots:y={},type:j="page",variant:S="text"}=a,h=It(a,mr),p=re({},a,{color:r,disabled:l,selected:g,shape:f,size:m,type:j,variant:S}),w=ct(),I=jr(p),O=(w.direction==="rtl"?{previous:y.next||c.next||ps,next:y.previous||c.previous||us,last:y.first||c.first||ls,first:y.last||c.last||ds}:{previous:y.previous||c.previous||us,next:y.next||c.next||ps,first:y.first||c.first||ls,last:y.last||c.last||ds})[j];return j==="start-ellipsis"||j==="end-ellipsis"?t.jsx(br,{ref:n,ownerState:p,className:Dt(I.root,o),children:"…"}):t.jsxs(Sr,re({ref:n,ownerState:p,component:i,disabled:l,className:Dt(I.root,o)},h,{children:[j==="page"&&d,O?t.jsx(vr,{as:O,ownerState:p,className:I.icon}):null]}))}),wr=["boundaryCount","className","color","count","defaultPage","disabled","getItemAriaLabel","hideNextButton","hidePrevButton","onChange","page","renderItem","shape","showFirstButton","showLastButton","siblingCount","size","variant"],Tr=e=>{const{classes:s,variant:n}=e;return Ms({root:["root",n],ul:["ul"]},hr,s)},Er=u("nav",{name:"MuiPagination",slot:"Root",overridesResolver:(e,s)=>{const{ownerState:n}=e;return[s.root,s[n.variant]]}})({}),Rr=u("ul",{name:"MuiPagination",slot:"Ul",overridesResolver:(e,s)=>s.ul})({display:"flex",flexWrap:"wrap",alignItems:"center",padding:0,margin:0,listStyle:"none"});function Ar(e,s,n){return e==="page"?`${n?"":"Go to "}page ${s}`:`Go to ${e} page`}const Dr=x.forwardRef(function(s,n){const a=_s({props:s,name:"MuiPagination"}),{boundaryCount:o=1,className:r,color:i="standard",count:c=1,defaultPage:l=1,disabled:d=!1,getItemAriaLabel:g=Ar,hideNextButton:f=!1,hidePrevButton:m=!1,renderItem:y=R=>t.jsx(Cr,re({},R)),shape:j="circular",showFirstButton:S=!1,showLastButton:h=!1,siblingCount:p=1,size:w="medium",variant:I="text"}=a,B=It(a,wr),{items:O}=xr(re({},a,{componentName:"Pagination"})),$=re({},a,{boundaryCount:o,color:i,count:c,defaultPage:l,disabled:d,getItemAriaLabel:g,hideNextButton:f,hidePrevButton:m,renderItem:y,shape:j,showFirstButton:S,showLastButton:h,siblingCount:p,size:w,variant:I}),P=Tr($);return t.jsx(Er,re({"aria-label":"pagination navigation",className:Dt(P.root,r),ownerState:$,ref:n},B,{children:t.jsx(Rr,{className:P.ul,ownerState:$,children:O.map((R,E)=>t.jsx("li",{children:y(re({},R,{color:i,"aria-label":g(R.type,R.page,R.selected),shape:j,size:w,variant:I}))},E))})}))}),kr=()=>{const e=k("projectId"),s=k("featureId"),{feature:n}=W(e,s);return n.name?t.jsx(In,{title:"Event log",feature:s}):null},$r=u(ne)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),dn=({isOpen:e,onClose:s,features:n,project:a})=>t.jsxs(be,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:s,children:[t.jsx("p",{children:"The following features depend on your feature:"}),t.jsx("ul",{children:n.map(o=>t.jsx("li",{children:t.jsx($r,{to:`/projects/${a}/features/${o}`,target:"_blank",rel:"noopener noreferrer",children:o})},o))})]}),Ge=u("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),De=u("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...Pn})),Je=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Wt=u(ne)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),Fr=()=>t.jsxs(he,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t.jsx(Ir,{}),"."]}),Ir=()=>t.jsx("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),Pr=u(Bn)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Br=({project:e,parent:s,onSelect:n,selectedValues:a})=>{const{parentVariantOptions:o}=Xo(e,s),r=t.jsx(On,{fontSize:"small"}),i=t.jsx(_n,{fontSize:"small"});return t.jsx(Pr,{multiple:!0,id:"parent-variant-options",options:o,disableCloseOnSelect:!0,renderOption:(c,l,{selected:d})=>t.jsxs("li",{...c,children:[t.jsx(zs,{icon:r,checkedIcon:i,style:{marginRight:8},checked:d}),l]}),renderInput:c=>t.jsx(Ln,{...c,placeholder:"Select values"}),fullWidth:!0,value:a,onChange:(c,l)=>{n(l)}})},me={key:"none (remove dependency)",label:"none (remove dependency)"},un=u(Pt)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Lr=({onSelect:e,parentValue:s})=>t.jsx(un,{fullWidth:!0,options:[{key:"enabled",label:"enabled"},{key:"enabled_with_variants",label:"enabled with variants"},{key:"disabled",label:"disabled"}],value:s.status,onChange:e}),pn=e=>{const{makeRequest:s,createRequest:n,errors:a,loading:o}=Mn({propagateErrors:!0}),r=async(d,g)=>{const f=n(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"POST",body:JSON.stringify(g)});await s(f.caller,f.id)},i=async(d,g)=>{const f=n(`/api/admin/projects/${e}/features/${d}/dependencies/${g}`,{method:"DELETE"});await s(f.caller,f.id)},c=async d=>{const g=n(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"DELETE"});await s(g.caller,g.id)},l=[n,s,G,e];return{addDependency:x.useCallback(r,l),removeDependency:x.useCallback(i,l),removeDependencies:x.useCallback(c,l),errors:a,loading:o}},Or=(e,s,n,a,o)=>{const{trackEvent:r}=Se(),{addChange:i}=Ee(),{refetch:c}=ve(e),{setToastData:l,setToastApiError:d}=ae(),{refetchFeature:g}=W(e,s),f=Bt(e)(),{isChangeRequestConfiguredInAnyEnv:m}=ce(e),{addDependency:y,removeDependencies:j}=pn(e),S=async h=>{if(!f){console.error("No change request environment");return}h==="addDependency"&&(await i(e,f,[{action:h,feature:s,payload:{feature:n,enabled:a.status!=="disabled",variants:a.status==="enabled_with_variants"?a.variants:[]}}]),r("dependent_features",{props:{eventType:"dependency added"}})),h==="deleteDependency"&&await i(e,f,[{action:h,feature:s,payload:void 0}]),c(),l({text:h==="addDependency"?`${s} will depend on ${n}`:`${s} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(m()){const h=n===me.key?"deleteDependency":"addDependency";await S(h),r("dependent_features",{props:{eventType:h==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else n===me.key?(await j(s),r("dependent_features",{props:{eventType:"dependency removed"}}),l({title:"Dependency removed",type:"success"})):(await y(s,{feature:n,enabled:a.status!=="disabled",variants:a.status==="enabled_with_variants"?a.variants:[]}),r("dependent_features",{props:{eventType:"dependency added"}}),l({title:"Dependency added",type:"success"}))}catch(h){d(G(h))}g(),o()}},_r=({project:e,featureId:s,parent:n,onSelect:a})=>{const{parentOptions:o}=Zo(e,s),r=o?[me,...o.map(i=>({key:i,label:i}))]:[me];return t.jsx(un,{fullWidth:!0,options:r,value:n,onChange:a})},Mr=({project:e,featureId:s,parentDependency:n,showDependencyDialogue:a,onClose:o})=>{const[r,i]=x.useState((n==null?void 0:n.feature)||me.key),c=()=>{var p;return n?(p=n.variants)!=null&&p.length?{status:"enabled_with_variants",variants:n.variants}:n.enabled===!1?{status:"disabled"}:{status:"enabled"}:{status:"enabled"}},[l,d]=x.useState(c),g=()=>{i((n==null?void 0:n.feature)||me.key),d(c())};x.useEffect(()=>{g()},[JSON.stringify(n)]);const f=Or(e,s,r,l,o),{isChangeRequestConfiguredInAnyEnv:m}=ce(e),y=r!==me.key,j=r!==me.key&&l.status==="enabled_with_variants",S=p=>{(p==="enabled"||p==="disabled")&&d({status:p}),p==="enabled_with_variants"&&d({status:p,variants:[]})},h=p=>{d({status:"enabled_with_variants",variants:p})};return t.jsx(be,{open:a,title:"Add parent feature dependency",onClose:o,onClick:f,primaryButtonText:m()?"Add change to draft":r===me.key?"Remove":"Add",secondaryButtonText:"Cancel",children:t.jsxs(Q,{children:[t.jsx(Fr,{}),t.jsxs(Q,{sx:{mt:2,mb:4},children:["Your feature will be evaluated only when the selected parent feature is"," ",t.jsx("b",{children:l.status==="disabled"?"disabled":"enabled"})," ","in the same environment."]}),t.jsxs(J,{children:["What ",t.jsx("b",{children:"feature"})," do you want to depend on?"]}),t.jsx(C,{condition:a,show:t.jsx(_r,{project:e,featureId:s,parent:r,onSelect:p=>{d({status:"enabled"}),i(p)}})}),t.jsx(C,{condition:y,show:t.jsxs(Q,{sx:{mt:2},children:[t.jsxs(J,{children:["What ",t.jsx("b",{children:"feature status"})," do you want to depend on?"]}),t.jsx(Lr,{parentValue:l,onSelect:S})]})}),t.jsx(C,{condition:j,show:l.status==="enabled_with_variants"&&t.jsxs(Q,{sx:{mt:2},children:[t.jsxs(J,{children:["What ",t.jsx("b",{children:"variant"})," do you want to depend on?"]}),t.jsx(Br,{parent:r,project:e,selectedValues:l.variants,onSelect:h})]})})]})})},zr=u(Vs)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),Vr=({feature:e,onEdit:s,onDelete:n})=>{const a=`dependency-${e}-actions`,o=`${a}-menu`,[r,i]=x.useState(null),c=!!r,l=g=>{i(g.currentTarget)},d=()=>{i(null)};return t.jsxs(Q,{children:[t.jsx(ue,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t.jsx(Qe,{sx:{mr:.25},id:a,"aria-controls":c?o:void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:l,type:"button",children:t.jsx(Lt,{})})}),t.jsx(zr,{id:o,anchorEl:r,open:c,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:t.jsxs(zn,{"aria-labelledby":a,children:[t.jsxs(we,{onClick:()=>{s(),d()},children:[t.jsx(Me,{children:t.jsx(ze,{})}),t.jsx(ke,{children:t.jsx(J,{variant:"body2",children:"Edit"})})]}),t.jsxs(we,{onClick:()=>{n(),d()},children:[t.jsx(Me,{children:t.jsx(Ns,{})}),t.jsx(ke,{children:t.jsx(J,{variant:"body2",children:"Delete"})})]})]})})]})},gn=({childFeatures:e,project:s})=>t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.map(n=>t.jsx(Wt,{to:`/projects/${s}/features/${n}`,children:t.jsx("div",{children:n})},`${s}-${n}`))}),children:e.length===1?"1 feature":`${e.length} features`}),Nr=({variants:e})=>e.length===1&&e[0].length<20?t.jsx("span",{children:e[0]}):t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.map(s=>t.jsx("div",{children:s}))}),children:e.length===1?"1 variant":`${e.length} variants`}),qr=(e,s)=>{const{trackEvent:n}=Se(),{addChange:a}=Ee(),{refetch:o}=ve(e),{setToastData:r,setToastApiError:i}=ae(),{refetchFeature:c}=W(e,s),l=Bt(e)(),{isChangeRequestConfiguredInAnyEnv:d}=ce(e),{removeDependencies:g}=pn(e),f=async()=>{if(!l){console.error("No change request environment");return}await a(e,l,[{action:"deleteDependency",feature:s,payload:void 0}])};return async()=>{try{d()?(await f(),n("dependent_features",{props:{eventType:"delete dependency added to change request"}}),r({text:`${s} dependency will be removed`,type:"success",title:"Change added to a draft"}),await o()):(await g(s),n("dependent_features",{props:{eventType:"dependency removed"}}),r({title:"Dependency removed",type:"success"}),await c())}catch(y){i(G(y))}}},Wr=({feature:e})=>{var d,g,f,m,y,j;const[s,n]=x.useState(!1),a=!!e.project&&e.dependencies.length===0&&e.children.length===0,o=!!e.project&&e.dependencies.length>0,r=!!e.project&&e.children.length>0,i=Bt(e.project)(),c=qs(e.project),l=qr(e.project,e.name);return t.jsxs(t.Fragment,{children:[t.jsx(C,{condition:a,show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency:"}),t.jsx(Te,{size:"small",permission:Kt,projectId:e.project,variant:"text",onClick:()=>{n(!0)},sx:S=>({marginBottom:S.spacing(.4)}),children:"Add parent feature"})]})})}),t.jsx(C,{condition:o,show:t.jsxs(Ge,{children:[t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency:"}),t.jsx(Wt,{to:`/projects/${e.project}/features/${(d=e.dependencies[0])==null?void 0:d.feature}`,children:(g=e.dependencies[0])==null?void 0:g.feature})]}),t.jsx(C,{condition:c(Kt,i),show:t.jsx(Vr,{feature:e.name,onEdit:()=>n(!0),onDelete:l})})]})}),t.jsx(C,{condition:o&&!((f=e.dependencies[0])!=null&&f.enabled),show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency value:"}),t.jsx("span",{children:"disabled"})]})})}),t.jsx(C,{condition:o&&!!((y=(m=e.dependencies[0])==null?void 0:m.variants)!=null&&y.length),show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency value:"}),t.jsx(Nr,{variants:((j=e.dependencies[0])==null?void 0:j.variants)||[]})]})})}),t.jsx(C,{condition:r,show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Children:"}),t.jsx(gn,{childFeatures:e.children,project:e.project})]})})}),t.jsx(C,{condition:!!e.project,show:t.jsx(Mr,{project:e.project,featureId:e.name,parentDependency:e.dependencies[0],onClose:()=>n(!1),showDependencyDialogue:s})})]})},Ur=(e,s={})=>{const n=Fe(`/api/admin/projects/${e}/dependencies`),{data:a,error:o}=Ws(e,!1,n,Hr,s);return{dependenciesExist:a,error:o,loading:!o&&!a}},Hr=async e=>await(await fetch(e).then(qe("Dependencies exist check"))).json(),Yr=e=>{const{dependenciesExist:s}=Ur(e),{isOss:n}=We();return!!e&&!!(!n()||s)},Gr=u("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),Jr=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Kr=u("div")({display:"flex",alignItems:"center"}),Qr=u("h2")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",margin:0})),Xr=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column",fontSize:e.fontSizes.smallBody})),yt=u("div")(({theme:e})=>({})),gs=u("div")(({theme:e})=>({display:"flex",justifyContent:"space-between",padding:e.spacing(1,0)})),hs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),fs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Zr=u("p")({wordBreak:"break-word"}),ei=u(Vn)(({theme:e})=>({margin:e.spacing(1)})),Ke=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),ti=()=>{var h;const e=k("projectId"),s=k("featureId"),{feature:n,refetchFeature:a}=W(e,s),{project:o,description:r,type:i}=n,c=Re(),[l,d]=x.useState(!1),[g,f]=x.useState(!1),{locationSettings:m}=Us(),y=Yr(n.project),j=(h=n.environments)==null?void 0:h.map(p=>({name:p.name,lastSeenAt:p.lastSeenAt,enabled:p.enabled,yes:p.yes,no:p.no})),S=Un(i);return t.jsxs(Gr,{children:[t.jsxs(Jr,{children:[t.jsxs(Kr,{"data-loading":!0,children:[t.jsx(S,{sx:p=>({marginRight:p.spacing(2),height:"40px",width:"40px",padding:p.spacing(.5),backgroundColor:p.palette.background.alternative,fill:p.palette.primary.contrastText,borderRadius:`${p.shape.borderRadiusMedium}px`})})," ",t.jsxs(Qr,{children:[Oe(i||"")," toggle"]})]}),t.jsxs(Xr,{children:[t.jsxs(gs,{"data-loading":!0,children:[t.jsx(Ke,{children:"Project:"}),t.jsx(Q,{sx:{wordBreak:"break-all"},children:o})]}),t.jsx(C,{condition:!!n.lifecycle,show:t.jsxs(gs,{"data-loading":!0,children:[t.jsx(Ke,{children:"Lifecycle:"}),t.jsx(Nn,{feature:n,onArchive:()=>d(!0),onComplete:()=>f(!0),onUncomplete:a})]})}),t.jsx(C,{condition:!!r,show:t.jsxs(yt,{"data-loading":!0,sx:{pt:1},children:[t.jsx(Ke,{children:"Description:"}),t.jsxs(hs,{children:[t.jsx(Zr,{children:r}),t.jsx(je,{size:"medium",projectId:e,permission:Ve,component:ne,to:`/projects/${e}/features/${s}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(ze,{})})]})]}),elseShow:t.jsx("div",{"data-loading":!0,children:t.jsxs(hs,{children:["No description."," ",t.jsx(je,{size:"medium",projectId:e,permission:Ve,component:ne,to:`/projects/${e}/features/${s}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(ze,{})})]})})}),t.jsx(yt,{children:t.jsxs(fs,{children:[t.jsxs(De,{children:[t.jsx(Ke,{children:"Created at:"}),t.jsx("span",{children:qn(Hs(n.createdAt),m.locale)})]}),t.jsx(Wn,{featureLastSeen:n.lastSeenAt,environments:j})]})}),t.jsx(C,{condition:!!n.createdBy,show:()=>{var p;return t.jsx(yt,{children:t.jsxs(fs,{children:[t.jsxs(De,{children:[t.jsx(Ke,{children:"Created by:"}),t.jsx("span",{children:(p=n.createdBy)==null?void 0:p.name})]}),t.jsx(ei,{user:n.createdBy})]})})}}),t.jsx(C,{condition:y,show:t.jsx(Wr,{feature:n})})]})]}),t.jsx(C,{condition:n.children.length>0,show:t.jsx(dn,{features:n.children,project:e,isOpen:l,onClose:()=>d(!1)}),elseShow:t.jsx(rn,{isOpen:l,onConfirm:()=>{c(`/projects/${e}`)},onClose:()=>d(!1),projectId:e,featureIds:[s]})}),t.jsx(C,{condition:!!n.project,show:t.jsx(er,{isOpen:g,setIsOpen:f,projectId:n.project,featureId:n.name,onComplete:a})})]})},xs={lastHourUsage:[],seenApplications:[]},si=(e,s,n={})=>{const a=async()=>{const g=Fe(`api/admin/client-metrics/features/${s}`),f=await fetch(g,{method:"GET"}).then(qe("feature metrics"));return f.ok?f.json():xs},o=`${e}_${s}_metrics`,{data:r,error:i}=Ys(o,a,{...n}),[c,l]=x.useState(!i&&!r),d=()=>{Ot(o)};return x.useEffect(()=>{l(!i&&!r)},[r,i]),{metrics:r||xs,error:i,loading:c,refetch:d,FEATURE_METRICS_CACHE_KEY:o}},ni=e=>({yes:0,no:0,environment:e,timestamp:""}),ai=(e,s)=>e.map(n=>s.lastHourUsage.find(o=>o.environment===n.name)||ni(n.name)),ys=Gs.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(s=>{e.status="fulfilled",e.value=s},s=>{e.status="rejected",e.reason=s}),e)}),mt={dedupe:!0},oi=(e,s,n)=>{const{cache:a,compare:o,suspense:r,fallbackData:i,revalidateOnMount:c,revalidateIfStale:l,refreshInterval:d,refreshWhenHidden:g,refreshWhenOffline:f,keepPreviousData:m}=n,[y,j,S,h]=Qn.get(a),[p,w]=Xn(e),I=x.useRef(!1),B=x.useRef(!1),O=x.useRef(p),$=x.useRef(s),P=x.useRef(n),R=()=>P.current,E=()=>R().isVisible()&&R().isOnline(),[_,X,te,b]=Zn(a,p),T=x.useRef({}).current,D=Y(i)?n.fallback[p]:i,v=(N,q)=>{for(const se in T){const H=se;if(H==="data"){if(!o(N[H],q[H])&&(!Y(N[H])||!o(U,q[H])))return!1}else if(q[H]!==N[H])return!1}return!0},F=x.useMemo(()=>{const N=!p||!s?!1:Y(c)?R().isPaused()||r?!1:Y(l)?!0:l:c,q=oe=>{const xe=oa(oe);return delete xe._k,N?{isValidating:!0,isLoading:!0,...xe}:xe},se=_(),H=b(),ge=q(se),Pe=se===H?ge:q(H);let ee=ge;return[()=>{const oe=q(_());return v(oe,ee)?(ee.data=oe.data,ee.isLoading=oe.isLoading,ee.isValidating=oe.isValidating,ee.error=oe.error,ee):(ee=oe,oe)},()=>Pe]},[a,p]),L=ea.useSyncExternalStore(x.useCallback(N=>te(p,(q,se)=>{v(se,q)||N()}),[a,p]),F[0],F[1]),V=!I.current,z=y[p]&&y[p].length>0,M=L.data,Z=Y(M)?D:M,ie=L.error,A=x.useRef(Z),U=m?Y(M)?A.current:M:Z,pe=z&&!Y(ie)?!1:V&&!Y(c)?c:R().isPaused()?!1:r?Y(Z)?!1:l:Y(Z)||l,K=!!(p&&s&&V&&pe),fe=Y(L.isValidating)?K:L.isValidating,Dn=Y(L.isLoading)?K:L.isLoading,He=x.useCallback(async N=>{const q=$.current;if(!p||!q||B.current||R().isPaused())return!1;let se,H,ge=!0;const Pe=N||{},ee=!S[p]||!Pe.dedupe,oe=()=>es?!B.current&&p===O.current&&I.current:p===O.current,xe={isValidating:!1,isLoading:!1},Yt=()=>{X(xe)},Gt=()=>{const le=S[p];le&&le[1]===H&&delete S[p]},Jt={isValidating:!0};Y(_().data)&&(Jt.isLoading=!0);try{if(ee&&(X(Jt),n.loadingTimeout&&Y(_().data)&&setTimeout(()=>{ge&&oe()&&R().onLoadingSlow(p,n)},n.loadingTimeout),S[p]=[q(w),ta()]),[se,H]=S[p],se=await se,ee&&setTimeout(Gt,n.dedupingInterval),!S[p]||S[p][1]!==H)return ee&&oe()&&R().onDiscarded(p),!1;xe.error=Qt;const le=j[p];if(!Y(le)&&(H<=le[0]||H<=le[1]||le[1]===0))return Yt(),ee&&oe()&&R().onDiscarded(p),!1;const ye=_().data;xe.data=o(ye,se)?ye:se,ee&&oe()&&R().onSuccess(se,p,n)}catch(le){Gt();const ye=R(),{shouldRetryOnError:ut}=ye;ye.isPaused()||(xe.error=le,ee&&oe()&&(ye.onError(le,p,ye),(ut===!0||Xt(ut)&&ut(le))&&(!R().revalidateOnFocus||!R().revalidateOnReconnect||E())&&ye.onErrorRetry(le,p,ye,kn=>{const pt=y[p];pt&&pt[0]&&pt[0](Ye.ERROR_REVALIDATE_EVENT,kn)},{retryCount:(Pe.retryCount||0)+1,dedupe:!0})))}return ge=!1,Yt(),!0},[p,a]),Ht=x.useCallback((...N)=>sa(a,O.current,...N),[]);if(gt(()=>{$.current=s,P.current=n,Y(M)||(A.current=M)}),gt(()=>{if(!p)return;const N=He.bind(Qt,mt);let q=0;const H=na(p,y,(ge,Pe={})=>{if(ge==Ye.FOCUS_EVENT){const ee=Date.now();R().revalidateOnFocus&&ee>q&&E()&&(q=ee+R().focusThrottleInterval,N())}else if(ge==Ye.RECONNECT_EVENT)R().revalidateOnReconnect&&E()&&N();else{if(ge==Ye.MUTATE_EVENT)return He();if(ge==Ye.ERROR_REVALIDATE_EVENT)return He(Pe)}});return B.current=!1,O.current=p,I.current=!0,X({_k:w}),pe&&(Y(Z)||Zt?N():aa(N)),()=>{B.current=!0,H()}},[p]),gt(()=>{let N;function q(){const H=Xt(d)?d(_().data):d;H&&N!==-1&&(N=setTimeout(se,H))}function se(){!_().error&&(g||R().isVisible())&&(f||R().isOnline())?He(mt).then(q):q()}return q(),()=>{N&&(clearTimeout(N),N=-1)}},[d,g,f,p]),x.useDebugValue(U),r&&Y(Z)&&p){if(!es&&Zt)throw new Error("Fallback data is required when using suspense in SSR.");$.current=s,P.current=n,B.current=!1;const N=h[p];if(!Y(N)){const q=Ht(N);ys(q)}if(Y(ie)){const q=He(mt);Y(U)||(q.status="fulfilled",q.value=!0),ys(q)}else throw ie}return{mutate:Ht,get data(){return T.data=!0,U},get error(){return T.error=!0,ie},get isValidating(){return T.isValidating=!0,fe},get isLoading(){return T.isLoading=!0,Dn}}};Hn.defineProperty(Yn,"defaultValue",{value:Gn});const ri=Kn(oi),ii=e=>(s,n,a)=>(a.revalidateOnFocus=!1,a.revalidateIfStale=!1,a.revalidateOnReconnect=!1,e(s,n,a)),ci=Jn(ri,ii),hn=(e,s)=>{const{refetchFeature:n}=W(e,s),a=ra(e,s),{data:o,error:r,mutate:i}=ci(["useFeatureImmutable",a],()=>ia(a)),c=x.useCallback(async()=>{await i(),await n()},[i,n]);return{feature:(o==null?void 0:o.body)||ca,refetchFeature:c,loading:!r&&!o,status:o==null?void 0:o.status,error:r}},fn=(e,s,n)=>{const{setToastData:a,setToastApiError:o}=ae(),{addChange:r}=Ee(),{refetch:i}=ve(e),[c,l]=x.useState({isOpen:!1}),d=x.useCallback((j,S,h)=>{l({featureName:s,environment:j,fromEnvironment:h,strategy:S,isOpen:!0})},[]),g=x.useCallback((j,S,h)=>{l({featureName:s,environment:j,fromEnvironment:h,strategies:S,isOpen:!0})},[]),f=x.useCallback(()=>{l({isOpen:!1})},[]),m=x.useCallback(async()=>{try{await r(e,c.environment,{feature:c.featureName,action:n,payload:c.strategy}),i(),l({isOpen:!1}),a({type:"success",title:"Changes added to the draft!"})}catch(j){o(G(j)),l({isOpen:!1})}},[r]),y=x.useCallback(async()=>{try{await Promise.all(c.strategies.map(j=>r(e,c.environment,{feature:c.featureName,action:n,payload:j}))),i(),l({isOpen:!1}),a({type:"success",title:"Changes added to the draft!"})}catch(j){o(G(j)),l({isOpen:!1})}},[r]);return{onChangeRequestAddStrategy:d,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:f,onChangeRequestAddStrategyConfirm:m,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:c}},li=({payload:e,fromEnvironment:s,environment:n})=>t.jsxs(J,{children:[t.jsxs("strong",{children:["Copy ",Ze((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",s," to ",n]}),di=({environmentId:e,environments:s,strategy:n})=>{const a=k("projectId"),o=k("featureId"),[r,i]=x.useState(null),c=!!r,{addStrategyToFeature:l}=Ue(),{setToastData:d,setToastApiError:g}=ae(),{refetchFeature:f}=W(a,o),{refetchFeature:m}=hn(a,o),y=()=>{i(null)},j=qs(a),{isChangeRequestConfigured:S}=ce(a),{changeRequestDialogDetails:h,onChangeRequestAddStrategyClose:p,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:I}=fn(a,o,"addStrategy"),B=async $=>{const{id:P,...R}={...n,targetEnvironment:$};if(S($)){await w($,R,e);return}try{await l(a,o,$,n),f(),m(),d({title:"Strategy created",text:`Successfully copied a strategy to ${$}`,type:"success"})}catch(E){g(G(E))}y()},O=s.some($=>j($e,$));return t.jsxs("div",{children:[t.jsx(cn,{isOpen:h.isOpen,onClose:p,environment:h==null?void 0:h.environment,onConfirm:I,messageComponent:t.jsx(li,{fromEnvironment:h.fromEnvironment,payload:h.strategy})}),t.jsx(ue,{title:`Copy to environment${O?"":" (Access denied)"}`,children:t.jsx("div",{children:t.jsx(Qe,{size:"large",id:`copy-strategy-icon-menu-${n.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:$=>{i($.currentTarget)},"data-testid":la,disabled:!O,children:t.jsx(da,{})})})}),t.jsx(et,{id:"basic-menu",anchorEl:r,open:c,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${n.id}`},children:[...s,e].map($=>{const P=j($e,$);return t.jsx(ue,{title:P?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(we,{onClick:()=>B($),disabled:!P,children:[t.jsx(C,{condition:!P,show:t.jsx(Me,{children:t.jsx(Js,{fontSize:"small"})})}),t.jsx(ke,{children:$===e?"Duplicate in current":`Copy to ${$}`})]})})},$)})})]})},ui=()=>t.jsx(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),pi=u("div")(({theme:e})=>({"> * + *":{marginTop:e.spacing(1)}})),gi=({changeRequests:e,projectId:s})=>e&&e.length>0?t.jsxs(he,{severity:"warning",children:[t.jsx("p",{children:"This strategy is in use by at least one scheduled change request. If you remove it, those change requests can no longer be applied."}),t.jsx("p",{children:"The following scheduled change requests use this strategy:"}),t.jsx("ul",{children:e.map(({id:n,title:a})=>{const o=a?`#${n} (${a})`:`#${n}`;return t.jsx("li",{children:t.jsx(ne,{to:`/projects/${s}/change-requests/${n}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${n}`,children:o})},n)})})]}):e===void 0?t.jsx(he,{severity:"warning",children:t.jsx("p",{children:"This strategy may be in use by one or more scheduled change requests. If you remove it, those change requests can no longer be applied."})}):null,xn=({scheduledChangeRequestsForStrategy:e})=>t.jsxs(pi,{children:[t.jsx(ui,{}),t.jsx(gi,{projectId:e.projectId,changeRequests:e.changeRequests})]}),hi=({onRemove:e,onClose:s,isOpen:n,scheduledChangeRequestsForStrategy:a})=>t.jsx(be,{title:"Are you sure you want to delete this strategy?",open:n,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:s,children:t.jsx(xn,{scheduledChangeRequestsForStrategy:a})}),fi=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),xi=({onRemove:e,onClose:s,isOpen:n,scheduledChangeRequestsForStrategy:a})=>t.jsxs(be,{title:"Suggest changes",open:n,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:s,children:[t.jsx(xn,{scheduledChangeRequestsForStrategy:a}),t.jsx(fi,{children:t.jsx(J,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t.jsx(J,{fontWeight:"bold",children:"Remove strategy"})]}),yi=({projectId:e,featureId:s,environmentId:n,strategyId:a})=>{const{deleteStrategyFromFeature:o}=Ue(),{setToastData:r,setToastApiError:i}=ae(),c=Re(),{refetchFeature:l}=W(e,s);return async g=>{try{g.preventDefault(),await o(e,s,n,a),r({title:"Strategy deleted",type:"success"}),l(),c(_t(e,s))}catch(f){i(G(f))}}},mi=({projectId:e,featureId:s,environmentId:n,strategyId:a})=>{const{addChange:o}=Ee(),{refetch:r}=ve(e),{setToastData:i,setToastApiError:c}=ae();return async d=>{try{d.preventDefault(),await o(e,n,{action:"deleteStrategy",feature:s,payload:{id:a}}),i({title:"Changes added to the draft!",type:"success"}),await r()}catch(g){c(G(g))}}},ji=({projectId:e,featureId:s,environmentId:n,strategyId:a,isOpen:o,onClose:r})=>{const{isChangeRequestConfigured:i}=ce(e),{changeRequests:c}=Ks(e,a),l={changeRequests:c,projectId:e},d=yi({featureId:s,projectId:e,strategyId:a,environmentId:n}),g=mi({featureId:s,projectId:e,strategyId:a,environmentId:n});return i(n)?t.jsx(xi,{isOpen:o,onClose:()=>r(),onRemove:async f=>{await g(f),r()},scheduledChangeRequestsForStrategy:l}):t.jsx(hi,{isOpen:o,onClose:()=>r(),onRemove:d,scheduledChangeRequestsForStrategy:l})},bi=({projectId:e,environmentId:s,featureId:n,strategy:a})=>{const{refetchFeature:o}=W(e,n),{setStrategyDisabledState:r}=Ue(),{setToastData:i,setToastApiError:c}=ae(),l=d=>async()=>{try{await r(e,n,s,a.id,!d),i({title:`Strategy ${d?"enabled":"disabled"}`,type:"success"}),o()}catch(g){c(G(g))}};return{onDisable:l(!1),onEnable:l(!0)}},Si=({projectId:e,environmentId:s,featureId:n,strategy:a})=>{const{addChange:o}=Ee(),{refetch:r}=ve(e),{setToastData:i,setToastApiError:c}=ae(),l=d=>async()=>{try{await o(e,s,{action:"updateStrategy",feature:n,payload:{...a,disabled:!d}}),i({title:"Changes added to the draft!",type:"success"}),await r()}catch(g){c(G(g))}};return{onSuggestDisable:l(!1),onSuggestEnable:l(!0)}},vi=({isOpen:e,onClose:s,...n})=>{var y;const{projectId:a,environmentId:o}=n,{isChangeRequestConfigured:r}=ce(a),i=r(o),{onSuggestEnable:c,onSuggestDisable:l}=Si({...n}),{onEnable:d,onDisable:g}=bi({...n}),f=!!((y=n.strategy)!=null&&y.disabled),m=j=>{j.preventDefault(),i?f?c():l():f?d():g(),s()};return t.jsx(be,{title:i?`Add ${f?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${f?"enable":"disable"} this strategy?`,open:e,primaryButtonText:i?"Add to draft":`${f?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:m,onClose:()=>s(),children:t.jsx(C,{condition:i,show:t.jsx(ua,{environment:o}),elseShow:t.jsxs(he,{severity:"error",children:[f?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})},Ci=({projectId:e,strategy:s,featureId:n,environmentId:a})=>{const[o,r]=x.useState(null),[i,c]=x.useState(!1),[l,d]=x.useState(!1),g=!!o,f=S=>{r(S.currentTarget)},m=S=>{r(null),S.stopPropagation()},y=kt(pa,e,a),j=kt(ga,e,a);return t.jsxs(t.Fragment,{children:[t.jsx(Q,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t.jsx(ue,{title:"More actions",children:t.jsx(Qe,{onClick:f,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":ha,children:t.jsx(Lt,{sx:{width:32,height:32}})})})}),t.jsxs(et,{anchorEl:o,id:"actions-menu",open:g,onClose:m,onClick:m,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":fa,children:[t.jsx(ue,{title:s.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:t.jsxs(we,{disabled:!y,onClick:()=>c(!0),children:[t.jsx(Me,{children:s.disabled?t.jsx(xa,{}):t.jsx(ya,{})}),t.jsx(ke,{children:s.disabled?"Enable":"Disable"})]})}),t.jsx(ue,{title:"Remove strategy",arrow:!0,placement:"left",children:t.jsxs(we,{disabled:!j,onClick:()=>d(!0),"data-testid":ma,children:[t.jsx(Me,{children:t.jsx(Ns,{})}),t.jsx(ke,{children:"Remove"})]})})]}),t.jsx(vi,{isOpen:i,onClose:()=>c(!1),projectId:e,featureId:n,environmentId:a,strategy:s}),t.jsx(ji,{isOpen:l,onClose:()=>d(!1),projectId:e,featureId:n,environmentId:a,strategyId:s.id})]})},wi=({environmentId:e,strategy:s,onDragStart:n,onDragEnd:a,otherEnvironments:o,orderNumber:r,headerChildren:i})=>{const c=k("projectId"),l=k("featureId"),d=ja(c,l,e,s.id);return t.jsxs(gr,{strategy:s,onDragStart:n,onDragEnd:a,orderNumber:r,actions:t.jsxs(t.Fragment,{children:[i,t.jsx(C,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t.jsx(di,{environmentId:e,environments:o,strategy:s})}),t.jsx(je,{permission:ba,environmentId:e,projectId:c,component:ne,to:d,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${s.name}`,children:t.jsx(ze,{})}),t.jsx(Ci,{projectId:c,featureId:l,environmentId:e,strategy:s})]}),children:[t.jsx(Sa,{strategy:s}),s.variants&&s.variants.length>0&&(s.disabled?t.jsx(Q,{sx:{opacity:"0.5"},children:t.jsx(ts,{variants:s.variants})}):t.jsx(ts,{variants:s.variants}))]})},Ti=e=>fetch(e).then(qe("ChangeRequest")).then(s=>s.json()),yn=(e,s)=>{const{data:n,error:a,mutate:o}=Qs([],Fe(`api/admin/projects/${e}/change-requests/pending/${s}`),Ti);return{changeRequests:n,loading:!a&&!n,refetch:o,error:a}},Ei=(e,s,n,a)=>{const{user:o}=va(),{changeRequests:r}=yn(e,s),i=[],c=r==null?void 0:r.filter(l=>l.environment===n);return c==null||c.forEach(l=>{const d=l==null?void 0:l.features.find(f=>f.name===s),g=d==null?void 0:d.changes.find(f=>f.action==="updateStrategy"||f.action==="deleteStrategy"?f.payload.id===a:!1);if(g){const f=l.state==="Scheduled",m=!f&&l.createdBy.id===(o==null?void 0:o.id);f&&i.push({changeRequestId:l.id,change:g,isScheduledChange:f}),m&&i.push({changeRequestId:l.id,change:g,isScheduledChange:f})}}),i},mn=({scheduledChangeRequestIds:e})=>{const s=ct(),n=tt(s.breakpoints.down("sm")),a=k("projectId");return n?null:t.jsx(Q,{sx:{mr:1.5},children:t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e==null?void 0:e.map((o,r)=>t.jsxs(Wt,{to:`/projects/${a}/change-requests/${o}`,children:["Change request #",o]},`${a}-${r}`))}),children:t.jsx(Ne,{color:"warning",children:"Changes Scheduled"})})})},ms=({strategy:e,index:s,environmentName:n,otherEnvironments:a,isDragging:o,onDragStartRef:r,onDragOver:i,onDragEnd:c})=>{const l=k("projectId"),d=k("featureId"),g=x.useRef(null),f=Ei(l,d,n,e.id),{changeRequests:m}=Ks(l,e.id);return t.jsxs(Q,{ref:g,onDragOver:i(g,s),sx:{opacity:o?"0.5":"1"},children:[t.jsx(C,{condition:s>0,show:t.jsx(Ca,{text:"OR"})}),t.jsx(wi,{strategy:e,environmentId:n,otherEnvironments:a,onDragStart:r(g,s),onDragEnd:c,orderNumber:s+1,headerChildren:Ai(f,m)})]},e.id)},Ri=({change:e})=>{const s=ct();return tt(s.breakpoints.down("sm"))?null:t.jsxs(Q,{sx:{mr:1.5},children:[t.jsx(C,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t.jsx(Ne,{color:"warning",children:"Modified in draft"})}),t.jsx(C,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t.jsx(Ne,{color:"error",children:"Deleted in draft"})})]})},Ai=(e,s)=>{const n=[];if((e==null?void 0:e.length)===0&&(s==null?void 0:s.length)===0)return[];const a=e==null?void 0:e.find(({isScheduledChange:o})=>!o);return a&&n.push(t.jsx(Ri,{change:a.change},`draft-change#${a.change.id}`)),s&&s.length>0&&n.push(t.jsx(mn,{scheduledChangeRequestIds:s.map(o=>o.id)},"scheduled-changes")),n},Di=({environmentId:e,environments:s,onClick:n})=>{const a=k("projectId"),[o,r]=x.useState(null),i=!!o,{hasAccess:c}=x.useContext(Mt),l=s.some(d=>c($e,a,d));return t.jsxs("div",{children:[t.jsx(ue,{title:l?"":"(Access denied)",children:t.jsx("div",{children:t.jsx(Ie,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:d=>{r(d.currentTarget)},disabled:!l,variant:"outlined",children:"Copy from another environment"})})}),t.jsx(et,{id:"basic-menu",anchorEl:o,open:i,onClose:()=>{r(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:s.map(d=>{const g=c($e,a,d);return t.jsx(ue,{title:g?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(we,{onClick:()=>n(d),disabled:!g,children:[t.jsx(C,{condition:!g,show:t.jsx(Me,{children:t.jsx(Js,{fontSize:"small"})})}),t.jsxs(ke,{children:["Copy from ",d]})]})})},d)})})]})},ki=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),$i=({payload:e,fromEnvironment:s,environment:n})=>t.jsxs(ki,{children:[t.jsx(J,{children:t.jsx("strong",{children:"Copy: "})}),e==null?void 0:e.map(a=>t.jsxs(J,{children:[t.jsxs("strong",{children:[Ze((a==null?void 0:a.name)||"")," strategy"," "]})," "]})),t.jsxs(J,{children:["from ",s," to ",n]})]}),Fi=(e,s)=>{const n={};return s.parameters.forEach(a=>{n[a.name]=Ii(e,a)}),{name:s.name,constraints:[],parameters:n}},Ii=(e,s)=>s.name==="rollout"||s.name==="percentage"||s.type==="percentage"?"50":s.name==="stickiness"?"":s.name==="groupId"?e:s.type==="boolean"?"false":"",Pi=e=>{var o;const{uiConfig:s}=We(),n=((o=s.resourceLimits)==null?void 0:o.featureEnvironmentStrategies)||100,a=e>=n;return{limit:n,limitReached:a}},Bi=()=>{const[e,s]=x.useState(0),n=k("projectId"),a=k("featureId"),o=ss("environmentId"),r=ss("strategyName"),{strategy:i,defaultStrategyFallback:c}=tr(n,o),l=JSON.parse(wa().get("defaultStrategy")||"false"),{segments:d}=Ta(),g=(d||[]).filter(K=>{var fe;return(fe=i==null?void 0:i.segments)==null?void 0:fe.includes(K.id)}),[f,m]=x.useState({}),[y,j]=x.useState(l?g:[]),{strategyDefinition:S}=Ea(r),h=Ra(),{addStrategyToFeature:p,loading:w}=Ue(),{addChange:I}=Ee(),{setToastData:B,setToastApiError:O}=ae(),{uiConfig:$}=We(),{unleashUrl:P}=$,R=Re(),{feature:E,refetchFeature:_}=W(n,a),X=E==null?void 0:E.environments.find(K=>K.name===o),te=(X==null?void 0:X.strategies.length)||0,{limit:b,limitReached:T}=Pi(te),D=x.useRef(E),{isChangeRequestConfigured:v}=ce(n),{refetch:F}=ve(n),{trackEvent:L}=Se(),{data:V,staleDataNotification:z,forceRefreshCache:M}=Aa({unleashGetter:W,params:[n,a],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},E,{afterSubmitAction:_},La);x.useEffect(()=>{D.current.name===""&&E.name&&(M(E),D.current=E)},[E.name]),x.useEffect(()=>{var K;if(l){const fe=i||c;((K=fe.parameters)==null?void 0:K.groupId)===""&&a?m({...fe,parameters:{...fe.parameters,groupId:a}}):m(fe)}else S&&m(Fi(a,S))},[a,JSON.stringify(S),JSON.stringify(i),l]);const Z=async K=>{await p(n,a,o,K),B({title:"Strategy created",type:"success",confetti:!0})},ie=async K=>{await I(n,o,{action:"addStrategy",feature:a,payload:K}),B({title:"Strategy added to draft",type:"success",confetti:!0}),F()},A=Da(f,y),U=async()=>{L("strategyTitle",{props:{hasTitle:!!f.title,on:"create"}});try{v(o)?await ie(A):await Z(A),_(),R(_t(n,a))}catch(K){O(G(K))}};return!V||!V.project?null:t.jsxs(Xs,{modal:!0,description:ka,documentationLink:$a,documentationLinkLabel:Fa,disablePadding:!0,formatApiCode:()=>Li(n,a,o,A,P),children:[t.jsx(Ia,{projectId:n,feature:V,strategy:f,setStrategy:m,segments:y,setSegments:j,environmentId:o,onSubmit:U,loading:w,permission:$e,errors:h,isChangeRequest:v(o),tab:e,setTab:s,StrategyVariants:t.jsx(Pa,{strategy:f,setStrategy:m,environment:o,projectId:n,editable:!0}),Limit:t.jsx(Ba,{name:"strategies in this environment",shortName:"strategies",currentValue:te,limit:b}),disabled:T}),z]})},jn=(e,s,n,a,o=!1)=>{const r=new URLSearchParams({environmentId:n,strategyName:a,defaultStrategy:String(o)});return`/projects/${e}/features/${s}/strategies/create?${r}`},Li=(e,s,n,a,o)=>{if(!o)return"";const r=`${o}/api/admin/projects/${e}/features/${s}/environments/${n}/strategies`,i=JSON.stringify(a,void 0,2);return`curl --location --request POST '${r}' \\
|
|
1
|
+
import{aA as Ls,aB as Os,_ as It,aC as $n,a as re,aD as it,j as t,s as u,aE as Fn,aF as Be,r as x,aG as _s,b as ct,aH as Dt,aI as Oe,aJ as Ms,aK as k,aL as W,aM as In,L as ne,aN as be,aO as Pn,N as he,A as Bn,aP as zs,l as Ln,aQ as On,aR as _n,aS as Pt,u as Mn,h as G,an as Se,aT as Ee,aU as ve,e as ae,aV as Bt,aW as ce,B as Q,T as J,C,a5 as Vs,t as ue,w as Qe,aX as Lt,aY as zn,M as we,aZ as Me,a_ as ze,a$ as ke,b0 as Ns,b1 as Xe,b2 as qs,b3 as Te,b4 as Kt,b5 as Fe,b6 as Ws,b7 as qe,b8 as We,b9 as Vn,ba as Re,bb as Us,bc as Nn,bd as je,be as Ve,bf as qn,bg as Hs,bh as Wn,bi as Un,bj as Ys,bk as Ot,bl as Gs,bm as Hn,bn as Yn,bo as Gn,bp as Jn,bq as Kn,br as Qn,bs as Xn,bt as Zn,bu as Y,bv as ea,bw as ta,bx as Qt,by as Xt,bz as Ye,bA as sa,bB as gt,bC as na,bD as Zt,bE as aa,bF as es,bG as oa,bH as ra,bI as ia,bJ as ca,bK as Ze,bL as Ue,bM as $e,bN as la,bO as da,bP as et,bQ as Js,bR as Ks,bS as _t,bT as ua,bU as kt,bV as pa,bW as ga,bX as ha,bY as fa,bZ as xa,b_ as ya,b$ as ma,c0 as ja,c1 as ba,c2 as Sa,c3 as ts,c4 as Qs,c5 as va,ag as tt,H as Ne,Q as Ca,c6 as Mt,i as Ie,c7 as ss,c8 as wa,c9 as Ta,ca as Ea,cb as Ra,cc as Aa,cd as Da,ce as Xs,cf as ka,cg as $a,ch as Fa,ci as Ia,cj as Pa,ck as Ba,cl as La,Y as zt,cm as Zs,a1 as Oa,cn as Vt,co as _e,cp as en,cq as _a,cr as Ma,cs as Ce,ct as za,cu as Va,a0 as Na,am as qa,cv as Wa,cw as Ua,cx as Ha,cy as Ya,cz as Ga,cA as Ja,cB as Ka,cC as Qa,cD as Nt,cE as Xa,cF as lt,cG as Za,X as tn,D as dt,cH as eo,cI as to,cJ as so,cK as no,cL as sn,cM as ao,cN as nn,cO as Ae,cP as $t,cQ as oo,cR as an,cS as ro,cT as io,f as co,cU as lo,cV as ht,cW as ns,az as uo,cX as Le,cY as as,cZ as po,c_ as go,c$ as ho,ax as qt,ay as fo,as as os,d0 as xo,d1 as yo,d2 as mo,d3 as rs,af as at,x as jo,y as bo,d4 as So,a7 as ft,aj as vo,a9 as Co,aa as wo,ab as To,ac as Eo,ad as Ro,ae as Ao,d5 as Do,d6 as is,d7 as ko,d8 as $o,d9 as xt,da as Fo,db as Io,dc as Po,q as on,dd as Bo,de as cs,df as Lo,dg as Oo,dh as _o,di as Mo,dj as zo,dk as Vo,dl as No,ap as qo,dm as Wo,d as Uo,dn as Ho,dp as Yo,dq as Go,dr as Jo,ds as Ko,dt as Qo}from"./index-Cx91uh9W.js";import{u as Xo,a as Zo,F as rn,M as er,C as cn,b as tr,c as sr,d as nr,V as ar,e as or,f as rr,T as ir,g as cr,h as lr,i as dr,j as ur,k as pr}from"./FeatureStaleDialog-CrsbH2rq.js";import{S as gr}from"./StrategyItemContainer-Das6_30A.js";function hr(e){return Ls("MuiPagination",e)}Os("MuiPagination",["root","ul","outlined","text"]);const fr=["boundaryCount","componentName","count","defaultPage","disabled","hideNextButton","hidePrevButton","onChange","page","showFirstButton","showLastButton","siblingCount"];function xr(e={}){const{boundaryCount:s=1,componentName:n="usePagination",count:a=1,defaultPage:o=1,disabled:r=!1,hideNextButton:i=!1,hidePrevButton:c=!1,onChange:l,page:d,showFirstButton:g=!1,showLastButton:f=!1,siblingCount:m=1}=e,y=It(e,fr),[j,S]=$n({controlled:d,default:o,name:n,state:"page"}),h=(E,_)=>{d||S(_),l&&l(E,_)},p=(E,_)=>{const X=_-E+1;return Array.from({length:X},(te,b)=>E+b)},w=p(1,Math.min(s,a)),I=p(Math.max(a-s+1,s+1),a),B=Math.max(Math.min(j-m,a-s-m*2-1),s+2),O=Math.min(Math.max(j+m,s+m*2+2),I.length>0?I[0]-2:a-1),$=[...g?["first"]:[],...c?[]:["previous"],...w,...B>s+2?["start-ellipsis"]:s+1<a-s?[s+1]:[],...p(B,O),...O<a-s-1?["end-ellipsis"]:a-s>s?[a-s]:[],...I,...i?[]:["next"],...f?["last"]:[]],P=E=>{switch(E){case"first":return 1;case"previous":return j-1;case"next":return j+1;case"last":return a;default:return null}},R=$.map(E=>typeof E=="number"?{onClick:_=>{h(_,E)},type:"page",page:E,selected:E===j,disabled:r,"aria-current":E===j?"true":void 0}:{onClick:_=>{h(_,P(E))},type:E,page:P(E),selected:!1,disabled:r||E.indexOf("ellipsis")===-1&&(E==="next"||E==="last"?j>=a:j<=1)});return re({items:R},y)}function yr(e){return Ls("MuiPaginationItem",e)}const de=Os("MuiPaginationItem",["root","page","sizeSmall","sizeLarge","text","textPrimary","textSecondary","outlined","outlinedPrimary","outlinedSecondary","rounded","ellipsis","firstLast","previousNext","focusVisible","disabled","selected","icon"]),ls=it(t.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"}),"FirstPage"),ds=it(t.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"}),"LastPage"),us=it(t.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"}),"NavigateBefore"),ps=it(t.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}),"NavigateNext"),mr=["className","color","component","components","disabled","page","selected","shape","size","slots","type","variant"],ln=(e,s)=>{const{ownerState:n}=e;return[s.root,s[n.variant],s[`size${Oe(n.size)}`],n.variant==="text"&&s[`text${Oe(n.color)}`],n.variant==="outlined"&&s[`outlined${Oe(n.color)}`],n.shape==="rounded"&&s.rounded,n.type==="page"&&s.page,(n.type==="start-ellipsis"||n.type==="end-ellipsis")&&s.ellipsis,(n.type==="previous"||n.type==="next")&&s.previousNext,(n.type==="first"||n.type==="last")&&s.firstLast]},jr=e=>{const{classes:s,color:n,disabled:a,selected:o,size:r,shape:i,type:c,variant:l}=e,d={root:["root",`size${Oe(r)}`,l,i,n!=="standard"&&`${l}${Oe(n)}`,a&&"disabled",o&&"selected",{page:"page",first:"firstLast",last:"firstLast","start-ellipsis":"ellipsis","end-ellipsis":"ellipsis",previous:"previousNext",next:"previousNext"}[c]],icon:["icon"]};return Ms(d,yr,s)},br=u("div",{name:"MuiPaginationItem",slot:"Root",overridesResolver:ln})(({theme:e,ownerState:s})=>re({},e.typography.body2,{borderRadius:32/2,textAlign:"center",boxSizing:"border-box",minWidth:32,padding:"0 6px",margin:"0 3px",color:(e.vars||e).palette.text.primary,height:"auto",[`&.${de.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity}},s.size==="small"&&{minWidth:26,borderRadius:26/2,margin:"0 1px",padding:"0 4px"},s.size==="large"&&{minWidth:40,borderRadius:40/2,padding:"0 10px",fontSize:e.typography.pxToRem(15)})),Sr=u(Fn,{name:"MuiPaginationItem",slot:"Root",overridesResolver:ln})(({theme:e,ownerState:s})=>re({},e.typography.body2,{borderRadius:32/2,textAlign:"center",boxSizing:"border-box",minWidth:32,height:32,padding:"0 6px",margin:"0 3px",color:(e.vars||e).palette.text.primary,[`&.${de.focusVisible}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${de.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity},transition:e.transitions.create(["color","background-color"],{duration:e.transitions.duration.short}),"&:hover":{backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${de.selected}`]:{backgroundColor:(e.vars||e).palette.action.selected,"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette.action.selectedChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:Be(e.palette.action.selected,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:(e.vars||e).palette.action.selected}},[`&.${de.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.action.selectedChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette.action.selected,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)},[`&.${de.disabled}`]:{opacity:1,color:(e.vars||e).palette.action.disabled,backgroundColor:(e.vars||e).palette.action.selected}}},s.size==="small"&&{minWidth:26,height:26,borderRadius:26/2,margin:"0 1px",padding:"0 4px"},s.size==="large"&&{minWidth:40,height:40,borderRadius:40/2,padding:"0 10px",fontSize:e.typography.pxToRem(15)},s.shape==="rounded"&&{borderRadius:(e.vars||e).shape.borderRadius}),({theme:e,ownerState:s})=>re({},s.variant==="text"&&{[`&.${de.selected}`]:re({},s.color!=="standard"&&{color:(e.vars||e).palette[s.color].contrastText,backgroundColor:(e.vars||e).palette[s.color].main,"&:hover":{backgroundColor:(e.vars||e).palette[s.color].dark,"@media (hover: none)":{backgroundColor:(e.vars||e).palette[s.color].main}},[`&.${de.focusVisible}`]:{backgroundColor:(e.vars||e).palette[s.color].dark}},{[`&.${de.disabled}`]:{color:(e.vars||e).palette.action.disabled}})},s.variant==="outlined"&&{border:e.vars?`1px solid rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:`1px solid ${e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)"}`,[`&.${de.selected}`]:re({},s.color!=="standard"&&{color:(e.vars||e).palette[s.color].main,border:`1px solid ${e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / 0.5)`:Be(e.palette[s.color].main,.5)}`,backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / ${e.vars.palette.action.activatedOpacity})`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity),"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / calc(${e.vars.palette.action.activatedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity+e.palette.action.focusOpacity),"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${de.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette[s.color].mainChannel} / calc(${e.vars.palette.action.activatedOpacity} + ${e.vars.palette.action.focusOpacity}))`:Be(e.palette[s.color].main,e.palette.action.activatedOpacity+e.palette.action.focusOpacity)}},{[`&.${de.disabled}`]:{borderColor:(e.vars||e).palette.action.disabledBackground,color:(e.vars||e).palette.action.disabled}})})),vr=u("div",{name:"MuiPaginationItem",slot:"Icon",overridesResolver:(e,s)=>s.icon})(({theme:e,ownerState:s})=>re({fontSize:e.typography.pxToRem(20),margin:"0 -8px"},s.size==="small"&&{fontSize:e.typography.pxToRem(18)},s.size==="large"&&{fontSize:e.typography.pxToRem(22)})),Cr=x.forwardRef(function(s,n){const a=_s({props:s,name:"MuiPaginationItem"}),{className:o,color:r="standard",component:i,components:c={},disabled:l=!1,page:d,selected:g=!1,shape:f="circular",size:m="medium",slots:y={},type:j="page",variant:S="text"}=a,h=It(a,mr),p=re({},a,{color:r,disabled:l,selected:g,shape:f,size:m,type:j,variant:S}),w=ct(),I=jr(p),O=(w.direction==="rtl"?{previous:y.next||c.next||ps,next:y.previous||c.previous||us,last:y.first||c.first||ls,first:y.last||c.last||ds}:{previous:y.previous||c.previous||us,next:y.next||c.next||ps,first:y.first||c.first||ls,last:y.last||c.last||ds})[j];return j==="start-ellipsis"||j==="end-ellipsis"?t.jsx(br,{ref:n,ownerState:p,className:Dt(I.root,o),children:"…"}):t.jsxs(Sr,re({ref:n,ownerState:p,component:i,disabled:l,className:Dt(I.root,o)},h,{children:[j==="page"&&d,O?t.jsx(vr,{as:O,ownerState:p,className:I.icon}):null]}))}),wr=["boundaryCount","className","color","count","defaultPage","disabled","getItemAriaLabel","hideNextButton","hidePrevButton","onChange","page","renderItem","shape","showFirstButton","showLastButton","siblingCount","size","variant"],Tr=e=>{const{classes:s,variant:n}=e;return Ms({root:["root",n],ul:["ul"]},hr,s)},Er=u("nav",{name:"MuiPagination",slot:"Root",overridesResolver:(e,s)=>{const{ownerState:n}=e;return[s.root,s[n.variant]]}})({}),Rr=u("ul",{name:"MuiPagination",slot:"Ul",overridesResolver:(e,s)=>s.ul})({display:"flex",flexWrap:"wrap",alignItems:"center",padding:0,margin:0,listStyle:"none"});function Ar(e,s,n){return e==="page"?`${n?"":"Go to "}page ${s}`:`Go to ${e} page`}const Dr=x.forwardRef(function(s,n){const a=_s({props:s,name:"MuiPagination"}),{boundaryCount:o=1,className:r,color:i="standard",count:c=1,defaultPage:l=1,disabled:d=!1,getItemAriaLabel:g=Ar,hideNextButton:f=!1,hidePrevButton:m=!1,renderItem:y=R=>t.jsx(Cr,re({},R)),shape:j="circular",showFirstButton:S=!1,showLastButton:h=!1,siblingCount:p=1,size:w="medium",variant:I="text"}=a,B=It(a,wr),{items:O}=xr(re({},a,{componentName:"Pagination"})),$=re({},a,{boundaryCount:o,color:i,count:c,defaultPage:l,disabled:d,getItemAriaLabel:g,hideNextButton:f,hidePrevButton:m,renderItem:y,shape:j,showFirstButton:S,showLastButton:h,siblingCount:p,size:w,variant:I}),P=Tr($);return t.jsx(Er,re({"aria-label":"pagination navigation",className:Dt(P.root,r),ownerState:$,ref:n},B,{children:t.jsx(Rr,{className:P.ul,ownerState:$,children:O.map((R,E)=>t.jsx("li",{children:y(re({},R,{color:i,"aria-label":g(R.type,R.page,R.selected),shape:j,size:w,variant:I}))},E))})}))}),kr=()=>{const e=k("projectId"),s=k("featureId"),{feature:n}=W(e,s);return n.name?t.jsx(In,{title:"Event log",feature:s}):null},$r=u(ne)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),dn=({isOpen:e,onClose:s,features:n,project:a})=>t.jsxs(be,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:s,children:[t.jsx("p",{children:"The following features depend on your feature:"}),t.jsx("ul",{children:n.map(o=>t.jsx("li",{children:t.jsx($r,{to:`/projects/${a}/features/${o}`,target:"_blank",rel:"noopener noreferrer",children:o})},o))})]}),Ge=u("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),De=u("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...Pn})),Je=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Wt=u(ne)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),Fr=()=>t.jsxs(he,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t.jsx(Ir,{}),"."]}),Ir=()=>t.jsx("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),Pr=u(Bn)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Br=({project:e,parent:s,onSelect:n,selectedValues:a})=>{const{parentVariantOptions:o}=Xo(e,s),r=t.jsx(On,{fontSize:"small"}),i=t.jsx(_n,{fontSize:"small"});return t.jsx(Pr,{multiple:!0,id:"parent-variant-options",options:o,disableCloseOnSelect:!0,renderOption:(c,l,{selected:d})=>t.jsxs("li",{...c,children:[t.jsx(zs,{icon:r,checkedIcon:i,style:{marginRight:8},checked:d}),l]}),renderInput:c=>t.jsx(Ln,{...c,placeholder:"Select values"}),fullWidth:!0,value:a,onChange:(c,l)=>{n(l)}})},me={key:"none (remove dependency)",label:"none (remove dependency)"},un=u(Pt)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Lr=({onSelect:e,parentValue:s})=>t.jsx(un,{fullWidth:!0,options:[{key:"enabled",label:"enabled"},{key:"enabled_with_variants",label:"enabled with variants"},{key:"disabled",label:"disabled"}],value:s.status,onChange:e}),pn=e=>{const{makeRequest:s,createRequest:n,errors:a,loading:o}=Mn({propagateErrors:!0}),r=async(d,g)=>{const f=n(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"POST",body:JSON.stringify(g)});await s(f.caller,f.id)},i=async(d,g)=>{const f=n(`/api/admin/projects/${e}/features/${d}/dependencies/${g}`,{method:"DELETE"});await s(f.caller,f.id)},c=async d=>{const g=n(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"DELETE"});await s(g.caller,g.id)},l=[n,s,G,e];return{addDependency:x.useCallback(r,l),removeDependency:x.useCallback(i,l),removeDependencies:x.useCallback(c,l),errors:a,loading:o}},Or=(e,s,n,a,o)=>{const{trackEvent:r}=Se(),{addChange:i}=Ee(),{refetch:c}=ve(e),{setToastData:l,setToastApiError:d}=ae(),{refetchFeature:g}=W(e,s),f=Bt(e)(),{isChangeRequestConfiguredInAnyEnv:m}=ce(e),{addDependency:y,removeDependencies:j}=pn(e),S=async h=>{if(!f){console.error("No change request environment");return}h==="addDependency"&&(await i(e,f,[{action:h,feature:s,payload:{feature:n,enabled:a.status!=="disabled",variants:a.status==="enabled_with_variants"?a.variants:[]}}]),r("dependent_features",{props:{eventType:"dependency added"}})),h==="deleteDependency"&&await i(e,f,[{action:h,feature:s,payload:void 0}]),c(),l({text:h==="addDependency"?`${s} will depend on ${n}`:`${s} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(m()){const h=n===me.key?"deleteDependency":"addDependency";await S(h),r("dependent_features",{props:{eventType:h==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else n===me.key?(await j(s),r("dependent_features",{props:{eventType:"dependency removed"}}),l({title:"Dependency removed",type:"success"})):(await y(s,{feature:n,enabled:a.status!=="disabled",variants:a.status==="enabled_with_variants"?a.variants:[]}),r("dependent_features",{props:{eventType:"dependency added"}}),l({title:"Dependency added",type:"success"}))}catch(h){d(G(h))}g(),o()}},_r=({project:e,featureId:s,parent:n,onSelect:a})=>{const{parentOptions:o}=Zo(e,s),r=o?[me,...o.map(i=>({key:i,label:i}))]:[me];return t.jsx(un,{fullWidth:!0,options:r,value:n,onChange:a})},Mr=({project:e,featureId:s,parentDependency:n,showDependencyDialogue:a,onClose:o})=>{const[r,i]=x.useState((n==null?void 0:n.feature)||me.key),c=()=>{var p;return n?(p=n.variants)!=null&&p.length?{status:"enabled_with_variants",variants:n.variants}:n.enabled===!1?{status:"disabled"}:{status:"enabled"}:{status:"enabled"}},[l,d]=x.useState(c),g=()=>{i((n==null?void 0:n.feature)||me.key),d(c())};x.useEffect(()=>{g()},[JSON.stringify(n)]);const f=Or(e,s,r,l,o),{isChangeRequestConfiguredInAnyEnv:m}=ce(e),y=r!==me.key,j=r!==me.key&&l.status==="enabled_with_variants",S=p=>{(p==="enabled"||p==="disabled")&&d({status:p}),p==="enabled_with_variants"&&d({status:p,variants:[]})},h=p=>{d({status:"enabled_with_variants",variants:p})};return t.jsx(be,{open:a,title:"Add parent feature dependency",onClose:o,onClick:f,primaryButtonText:m()?"Add change to draft":r===me.key?"Remove":"Add",secondaryButtonText:"Cancel",children:t.jsxs(Q,{children:[t.jsx(Fr,{}),t.jsxs(Q,{sx:{mt:2,mb:4},children:["Your feature will be evaluated only when the selected parent feature is"," ",t.jsx("b",{children:l.status==="disabled"?"disabled":"enabled"})," ","in the same environment."]}),t.jsxs(J,{children:["What ",t.jsx("b",{children:"feature"})," do you want to depend on?"]}),t.jsx(C,{condition:a,show:t.jsx(_r,{project:e,featureId:s,parent:r,onSelect:p=>{d({status:"enabled"}),i(p)}})}),t.jsx(C,{condition:y,show:t.jsxs(Q,{sx:{mt:2},children:[t.jsxs(J,{children:["What ",t.jsx("b",{children:"feature status"})," do you want to depend on?"]}),t.jsx(Lr,{parentValue:l,onSelect:S})]})}),t.jsx(C,{condition:j,show:l.status==="enabled_with_variants"&&t.jsxs(Q,{sx:{mt:2},children:[t.jsxs(J,{children:["What ",t.jsx("b",{children:"variant"})," do you want to depend on?"]}),t.jsx(Br,{parent:r,project:e,selectedValues:l.variants,onSelect:h})]})})]})})},zr=u(Vs)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),Vr=({feature:e,onEdit:s,onDelete:n})=>{const a=`dependency-${e}-actions`,o=`${a}-menu`,[r,i]=x.useState(null),c=!!r,l=g=>{i(g.currentTarget)},d=()=>{i(null)};return t.jsxs(Q,{children:[t.jsx(ue,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t.jsx(Qe,{sx:{mr:.25},id:a,"aria-controls":c?o:void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:l,type:"button",children:t.jsx(Lt,{})})}),t.jsx(zr,{id:o,anchorEl:r,open:c,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:t.jsxs(zn,{"aria-labelledby":a,children:[t.jsxs(we,{onClick:()=>{s(),d()},children:[t.jsx(Me,{children:t.jsx(ze,{})}),t.jsx(ke,{children:t.jsx(J,{variant:"body2",children:"Edit"})})]}),t.jsxs(we,{onClick:()=>{n(),d()},children:[t.jsx(Me,{children:t.jsx(Ns,{})}),t.jsx(ke,{children:t.jsx(J,{variant:"body2",children:"Delete"})})]})]})})]})},gn=({childFeatures:e,project:s})=>t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.map(n=>t.jsx(Wt,{to:`/projects/${s}/features/${n}`,children:t.jsx("div",{children:n})},`${s}-${n}`))}),children:e.length===1?"1 feature":`${e.length} features`}),Nr=({variants:e})=>e.length===1&&e[0].length<20?t.jsx("span",{children:e[0]}):t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.map(s=>t.jsx("div",{children:s}))}),children:e.length===1?"1 variant":`${e.length} variants`}),qr=(e,s)=>{const{trackEvent:n}=Se(),{addChange:a}=Ee(),{refetch:o}=ve(e),{setToastData:r,setToastApiError:i}=ae(),{refetchFeature:c}=W(e,s),l=Bt(e)(),{isChangeRequestConfiguredInAnyEnv:d}=ce(e),{removeDependencies:g}=pn(e),f=async()=>{if(!l){console.error("No change request environment");return}await a(e,l,[{action:"deleteDependency",feature:s,payload:void 0}])};return async()=>{try{d()?(await f(),n("dependent_features",{props:{eventType:"delete dependency added to change request"}}),r({text:`${s} dependency will be removed`,type:"success",title:"Change added to a draft"}),await o()):(await g(s),n("dependent_features",{props:{eventType:"dependency removed"}}),r({title:"Dependency removed",type:"success"}),await c())}catch(y){i(G(y))}}},Wr=({feature:e})=>{var d,g,f,m,y,j;const[s,n]=x.useState(!1),a=!!e.project&&e.dependencies.length===0&&e.children.length===0,o=!!e.project&&e.dependencies.length>0,r=!!e.project&&e.children.length>0,i=Bt(e.project)(),c=qs(e.project),l=qr(e.project,e.name);return t.jsxs(t.Fragment,{children:[t.jsx(C,{condition:a,show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency:"}),t.jsx(Te,{size:"small",permission:Kt,projectId:e.project,variant:"text",onClick:()=>{n(!0)},sx:S=>({marginBottom:S.spacing(.4)}),children:"Add parent feature"})]})})}),t.jsx(C,{condition:o,show:t.jsxs(Ge,{children:[t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency:"}),t.jsx(Wt,{to:`/projects/${e.project}/features/${(d=e.dependencies[0])==null?void 0:d.feature}`,children:(g=e.dependencies[0])==null?void 0:g.feature})]}),t.jsx(C,{condition:c(Kt,i),show:t.jsx(Vr,{feature:e.name,onEdit:()=>n(!0),onDelete:l})})]})}),t.jsx(C,{condition:o&&!((f=e.dependencies[0])!=null&&f.enabled),show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency value:"}),t.jsx("span",{children:"disabled"})]})})}),t.jsx(C,{condition:o&&!!((y=(m=e.dependencies[0])==null?void 0:m.variants)!=null&&y.length),show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Dependency value:"}),t.jsx(Nr,{variants:((j=e.dependencies[0])==null?void 0:j.variants)||[]})]})})}),t.jsx(C,{condition:r,show:t.jsx(Ge,{children:t.jsxs(De,{children:[t.jsx(Je,{children:"Children:"}),t.jsx(gn,{childFeatures:e.children,project:e.project})]})})}),t.jsx(C,{condition:!!e.project,show:t.jsx(Mr,{project:e.project,featureId:e.name,parentDependency:e.dependencies[0],onClose:()=>n(!1),showDependencyDialogue:s})})]})},Ur=(e,s={})=>{const n=Fe(`/api/admin/projects/${e}/dependencies`),{data:a,error:o}=Ws(e,!1,n,Hr,s);return{dependenciesExist:a,error:o,loading:!o&&!a}},Hr=async e=>await(await fetch(e).then(qe("Dependencies exist check"))).json(),Yr=e=>{const{dependenciesExist:s}=Ur(e),{isOss:n}=We();return!!e&&!!(!n()||s)},Gr=u("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),Jr=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Kr=u("div")({display:"flex",alignItems:"center"}),Qr=u("h2")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",margin:0})),Xr=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column",fontSize:e.fontSizes.smallBody})),yt=u("div")(({theme:e})=>({})),gs=u("div")(({theme:e})=>({display:"flex",justifyContent:"space-between",padding:e.spacing(1,0)})),hs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),fs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Zr=u("p")({wordBreak:"break-word"}),ei=u(Vn)(({theme:e})=>({margin:e.spacing(1)})),Ke=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),ti=()=>{var h;const e=k("projectId"),s=k("featureId"),{feature:n,refetchFeature:a}=W(e,s),{project:o,description:r,type:i}=n,c=Re(),[l,d]=x.useState(!1),[g,f]=x.useState(!1),{locationSettings:m}=Us(),y=Yr(n.project),j=(h=n.environments)==null?void 0:h.map(p=>({name:p.name,lastSeenAt:p.lastSeenAt,enabled:p.enabled,yes:p.yes,no:p.no})),S=Un(i);return t.jsxs(Gr,{children:[t.jsxs(Jr,{children:[t.jsxs(Kr,{"data-loading":!0,children:[t.jsx(S,{sx:p=>({marginRight:p.spacing(2),height:"40px",width:"40px",padding:p.spacing(.5),backgroundColor:p.palette.background.alternative,fill:p.palette.primary.contrastText,borderRadius:`${p.shape.borderRadiusMedium}px`})})," ",t.jsxs(Qr,{children:[Oe(i||"")," toggle"]})]}),t.jsxs(Xr,{children:[t.jsxs(gs,{"data-loading":!0,children:[t.jsx(Ke,{children:"Project:"}),t.jsx(Q,{sx:{wordBreak:"break-all"},children:o})]}),t.jsx(C,{condition:!!n.lifecycle,show:t.jsxs(gs,{"data-loading":!0,children:[t.jsx(Ke,{children:"Lifecycle:"}),t.jsx(Nn,{feature:n,onArchive:()=>d(!0),onComplete:()=>f(!0),onUncomplete:a})]})}),t.jsx(C,{condition:!!r,show:t.jsxs(yt,{"data-loading":!0,sx:{pt:1},children:[t.jsx(Ke,{children:"Description:"}),t.jsxs(hs,{children:[t.jsx(Zr,{children:r}),t.jsx(je,{size:"medium",projectId:e,permission:Ve,component:ne,to:`/projects/${e}/features/${s}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(ze,{})})]})]}),elseShow:t.jsx("div",{"data-loading":!0,children:t.jsxs(hs,{children:["No description."," ",t.jsx(je,{size:"medium",projectId:e,permission:Ve,component:ne,to:`/projects/${e}/features/${s}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(ze,{})})]})})}),t.jsx(yt,{children:t.jsxs(fs,{children:[t.jsxs(De,{children:[t.jsx(Ke,{children:"Created at:"}),t.jsx("span",{children:qn(Hs(n.createdAt),m.locale)})]}),t.jsx(Wn,{featureLastSeen:n.lastSeenAt,environments:j})]})}),t.jsx(C,{condition:!!n.createdBy,show:()=>{var p;return t.jsx(yt,{children:t.jsxs(fs,{children:[t.jsxs(De,{children:[t.jsx(Ke,{children:"Created by:"}),t.jsx("span",{children:(p=n.createdBy)==null?void 0:p.name})]}),t.jsx(ei,{user:n.createdBy})]})})}}),t.jsx(C,{condition:y,show:t.jsx(Wr,{feature:n})})]})]}),t.jsx(C,{condition:n.children.length>0,show:t.jsx(dn,{features:n.children,project:e,isOpen:l,onClose:()=>d(!1)}),elseShow:t.jsx(rn,{isOpen:l,onConfirm:()=>{c(`/projects/${e}`)},onClose:()=>d(!1),projectId:e,featureIds:[s]})}),t.jsx(C,{condition:!!n.project,show:t.jsx(er,{isOpen:g,setIsOpen:f,projectId:n.project,featureId:n.name,onComplete:a})})]})},xs={lastHourUsage:[],seenApplications:[]},si=(e,s,n={})=>{const a=async()=>{const g=Fe(`api/admin/client-metrics/features/${s}`),f=await fetch(g,{method:"GET"}).then(qe("feature metrics"));return f.ok?f.json():xs},o=`${e}_${s}_metrics`,{data:r,error:i}=Ys(o,a,{...n}),[c,l]=x.useState(!i&&!r),d=()=>{Ot(o)};return x.useEffect(()=>{l(!i&&!r)},[r,i]),{metrics:r||xs,error:i,loading:c,refetch:d,FEATURE_METRICS_CACHE_KEY:o}},ni=e=>({yes:0,no:0,environment:e,timestamp:""}),ai=(e,s)=>e.map(n=>s.lastHourUsage.find(o=>o.environment===n.name)||ni(n.name)),ys=Gs.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(s=>{e.status="fulfilled",e.value=s},s=>{e.status="rejected",e.reason=s}),e)}),mt={dedupe:!0},oi=(e,s,n)=>{const{cache:a,compare:o,suspense:r,fallbackData:i,revalidateOnMount:c,revalidateIfStale:l,refreshInterval:d,refreshWhenHidden:g,refreshWhenOffline:f,keepPreviousData:m}=n,[y,j,S,h]=Qn.get(a),[p,w]=Xn(e),I=x.useRef(!1),B=x.useRef(!1),O=x.useRef(p),$=x.useRef(s),P=x.useRef(n),R=()=>P.current,E=()=>R().isVisible()&&R().isOnline(),[_,X,te,b]=Zn(a,p),T=x.useRef({}).current,D=Y(i)?n.fallback[p]:i,v=(N,q)=>{for(const se in T){const H=se;if(H==="data"){if(!o(N[H],q[H])&&(!Y(N[H])||!o(U,q[H])))return!1}else if(q[H]!==N[H])return!1}return!0},F=x.useMemo(()=>{const N=!p||!s?!1:Y(c)?R().isPaused()||r?!1:Y(l)?!0:l:c,q=oe=>{const xe=oa(oe);return delete xe._k,N?{isValidating:!0,isLoading:!0,...xe}:xe},se=_(),H=b(),ge=q(se),Pe=se===H?ge:q(H);let ee=ge;return[()=>{const oe=q(_());return v(oe,ee)?(ee.data=oe.data,ee.isLoading=oe.isLoading,ee.isValidating=oe.isValidating,ee.error=oe.error,ee):(ee=oe,oe)},()=>Pe]},[a,p]),L=ea.useSyncExternalStore(x.useCallback(N=>te(p,(q,se)=>{v(se,q)||N()}),[a,p]),F[0],F[1]),V=!I.current,z=y[p]&&y[p].length>0,M=L.data,Z=Y(M)?D:M,ie=L.error,A=x.useRef(Z),U=m?Y(M)?A.current:M:Z,pe=z&&!Y(ie)?!1:V&&!Y(c)?c:R().isPaused()?!1:r?Y(Z)?!1:l:Y(Z)||l,K=!!(p&&s&&V&&pe),fe=Y(L.isValidating)?K:L.isValidating,Dn=Y(L.isLoading)?K:L.isLoading,He=x.useCallback(async N=>{const q=$.current;if(!p||!q||B.current||R().isPaused())return!1;let se,H,ge=!0;const Pe=N||{},ee=!S[p]||!Pe.dedupe,oe=()=>es?!B.current&&p===O.current&&I.current:p===O.current,xe={isValidating:!1,isLoading:!1},Yt=()=>{X(xe)},Gt=()=>{const le=S[p];le&&le[1]===H&&delete S[p]},Jt={isValidating:!0};Y(_().data)&&(Jt.isLoading=!0);try{if(ee&&(X(Jt),n.loadingTimeout&&Y(_().data)&&setTimeout(()=>{ge&&oe()&&R().onLoadingSlow(p,n)},n.loadingTimeout),S[p]=[q(w),ta()]),[se,H]=S[p],se=await se,ee&&setTimeout(Gt,n.dedupingInterval),!S[p]||S[p][1]!==H)return ee&&oe()&&R().onDiscarded(p),!1;xe.error=Qt;const le=j[p];if(!Y(le)&&(H<=le[0]||H<=le[1]||le[1]===0))return Yt(),ee&&oe()&&R().onDiscarded(p),!1;const ye=_().data;xe.data=o(ye,se)?ye:se,ee&&oe()&&R().onSuccess(se,p,n)}catch(le){Gt();const ye=R(),{shouldRetryOnError:ut}=ye;ye.isPaused()||(xe.error=le,ee&&oe()&&(ye.onError(le,p,ye),(ut===!0||Xt(ut)&&ut(le))&&(!R().revalidateOnFocus||!R().revalidateOnReconnect||E())&&ye.onErrorRetry(le,p,ye,kn=>{const pt=y[p];pt&&pt[0]&&pt[0](Ye.ERROR_REVALIDATE_EVENT,kn)},{retryCount:(Pe.retryCount||0)+1,dedupe:!0})))}return ge=!1,Yt(),!0},[p,a]),Ht=x.useCallback((...N)=>sa(a,O.current,...N),[]);if(gt(()=>{$.current=s,P.current=n,Y(M)||(A.current=M)}),gt(()=>{if(!p)return;const N=He.bind(Qt,mt);let q=0;const H=na(p,y,(ge,Pe={})=>{if(ge==Ye.FOCUS_EVENT){const ee=Date.now();R().revalidateOnFocus&&ee>q&&E()&&(q=ee+R().focusThrottleInterval,N())}else if(ge==Ye.RECONNECT_EVENT)R().revalidateOnReconnect&&E()&&N();else{if(ge==Ye.MUTATE_EVENT)return He();if(ge==Ye.ERROR_REVALIDATE_EVENT)return He(Pe)}});return B.current=!1,O.current=p,I.current=!0,X({_k:w}),pe&&(Y(Z)||Zt?N():aa(N)),()=>{B.current=!0,H()}},[p]),gt(()=>{let N;function q(){const H=Xt(d)?d(_().data):d;H&&N!==-1&&(N=setTimeout(se,H))}function se(){!_().error&&(g||R().isVisible())&&(f||R().isOnline())?He(mt).then(q):q()}return q(),()=>{N&&(clearTimeout(N),N=-1)}},[d,g,f,p]),x.useDebugValue(U),r&&Y(Z)&&p){if(!es&&Zt)throw new Error("Fallback data is required when using suspense in SSR.");$.current=s,P.current=n,B.current=!1;const N=h[p];if(!Y(N)){const q=Ht(N);ys(q)}if(Y(ie)){const q=He(mt);Y(U)||(q.status="fulfilled",q.value=!0),ys(q)}else throw ie}return{mutate:Ht,get data(){return T.data=!0,U},get error(){return T.error=!0,ie},get isValidating(){return T.isValidating=!0,fe},get isLoading(){return T.isLoading=!0,Dn}}};Hn.defineProperty(Yn,"defaultValue",{value:Gn});const ri=Kn(oi),ii=e=>(s,n,a)=>(a.revalidateOnFocus=!1,a.revalidateIfStale=!1,a.revalidateOnReconnect=!1,e(s,n,a)),ci=Jn(ri,ii),hn=(e,s)=>{const{refetchFeature:n}=W(e,s),a=ra(e,s),{data:o,error:r,mutate:i}=ci(["useFeatureImmutable",a],()=>ia(a)),c=x.useCallback(async()=>{await i(),await n()},[i,n]);return{feature:(o==null?void 0:o.body)||ca,refetchFeature:c,loading:!r&&!o,status:o==null?void 0:o.status,error:r}},fn=(e,s,n)=>{const{setToastData:a,setToastApiError:o}=ae(),{addChange:r}=Ee(),{refetch:i}=ve(e),[c,l]=x.useState({isOpen:!1}),d=x.useCallback((j,S,h)=>{l({featureName:s,environment:j,fromEnvironment:h,strategy:S,isOpen:!0})},[]),g=x.useCallback((j,S,h)=>{l({featureName:s,environment:j,fromEnvironment:h,strategies:S,isOpen:!0})},[]),f=x.useCallback(()=>{l({isOpen:!1})},[]),m=x.useCallback(async()=>{try{await r(e,c.environment,{feature:c.featureName,action:n,payload:c.strategy}),i(),l({isOpen:!1}),a({type:"success",title:"Changes added to the draft!"})}catch(j){o(G(j)),l({isOpen:!1})}},[r]),y=x.useCallback(async()=>{try{await Promise.all(c.strategies.map(j=>r(e,c.environment,{feature:c.featureName,action:n,payload:j}))),i(),l({isOpen:!1}),a({type:"success",title:"Changes added to the draft!"})}catch(j){o(G(j)),l({isOpen:!1})}},[r]);return{onChangeRequestAddStrategy:d,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:f,onChangeRequestAddStrategyConfirm:m,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:c}},li=({payload:e,fromEnvironment:s,environment:n})=>t.jsxs(J,{children:[t.jsxs("strong",{children:["Copy ",Ze((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",s," to ",n]}),di=({environmentId:e,environments:s,strategy:n})=>{const a=k("projectId"),o=k("featureId"),[r,i]=x.useState(null),c=!!r,{addStrategyToFeature:l}=Ue(),{setToastData:d,setToastApiError:g}=ae(),{refetchFeature:f}=W(a,o),{refetchFeature:m}=hn(a,o),y=()=>{i(null)},j=qs(a),{isChangeRequestConfigured:S}=ce(a),{changeRequestDialogDetails:h,onChangeRequestAddStrategyClose:p,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:I}=fn(a,o,"addStrategy"),B=async $=>{const{id:P,...R}={...n,targetEnvironment:$};if(S($)){await w($,R,e);return}try{await l(a,o,$,n),f(),m(),d({title:"Strategy created",text:`Successfully copied a strategy to ${$}`,type:"success"})}catch(E){g(G(E))}y()},O=s.some($=>j($e,$));return t.jsxs("div",{children:[t.jsx(cn,{isOpen:h.isOpen,onClose:p,environment:h==null?void 0:h.environment,onConfirm:I,messageComponent:t.jsx(li,{fromEnvironment:h.fromEnvironment,payload:h.strategy})}),t.jsx(ue,{title:`Copy to environment${O?"":" (Access denied)"}`,children:t.jsx("div",{children:t.jsx(Qe,{size:"large",id:`copy-strategy-icon-menu-${n.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:$=>{i($.currentTarget)},"data-testid":la,disabled:!O,children:t.jsx(da,{})})})}),t.jsx(et,{id:"basic-menu",anchorEl:r,open:c,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${n.id}`},children:[...s,e].map($=>{const P=j($e,$);return t.jsx(ue,{title:P?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(we,{onClick:()=>B($),disabled:!P,children:[t.jsx(C,{condition:!P,show:t.jsx(Me,{children:t.jsx(Js,{fontSize:"small"})})}),t.jsx(ke,{children:$===e?"Duplicate in current":`Copy to ${$}`})]})})},$)})})]})},ui=()=>t.jsx(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),pi=u("div")(({theme:e})=>({"> * + *":{marginTop:e.spacing(1)}})),gi=({changeRequests:e,projectId:s})=>e&&e.length>0?t.jsxs(he,{severity:"warning",children:[t.jsx("p",{children:"This strategy is in use by at least one scheduled change request. If you remove it, those change requests can no longer be applied."}),t.jsx("p",{children:"The following scheduled change requests use this strategy:"}),t.jsx("ul",{children:e.map(({id:n,title:a})=>{const o=a?`#${n} (${a})`:`#${n}`;return t.jsx("li",{children:t.jsx(ne,{to:`/projects/${s}/change-requests/${n}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${n}`,children:o})},n)})})]}):e===void 0?t.jsx(he,{severity:"warning",children:t.jsx("p",{children:"This strategy may be in use by one or more scheduled change requests. If you remove it, those change requests can no longer be applied."})}):null,xn=({scheduledChangeRequestsForStrategy:e})=>t.jsxs(pi,{children:[t.jsx(ui,{}),t.jsx(gi,{projectId:e.projectId,changeRequests:e.changeRequests})]}),hi=({onRemove:e,onClose:s,isOpen:n,scheduledChangeRequestsForStrategy:a})=>t.jsx(be,{title:"Are you sure you want to delete this strategy?",open:n,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:s,children:t.jsx(xn,{scheduledChangeRequestsForStrategy:a})}),fi=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),xi=({onRemove:e,onClose:s,isOpen:n,scheduledChangeRequestsForStrategy:a})=>t.jsxs(be,{title:"Suggest changes",open:n,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:s,children:[t.jsx(xn,{scheduledChangeRequestsForStrategy:a}),t.jsx(fi,{children:t.jsx(J,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t.jsx(J,{fontWeight:"bold",children:"Remove strategy"})]}),yi=({projectId:e,featureId:s,environmentId:n,strategyId:a})=>{const{deleteStrategyFromFeature:o}=Ue(),{setToastData:r,setToastApiError:i}=ae(),c=Re(),{refetchFeature:l}=W(e,s);return async g=>{try{g.preventDefault(),await o(e,s,n,a),r({title:"Strategy deleted",type:"success"}),l(),c(_t(e,s))}catch(f){i(G(f))}}},mi=({projectId:e,featureId:s,environmentId:n,strategyId:a})=>{const{addChange:o}=Ee(),{refetch:r}=ve(e),{setToastData:i,setToastApiError:c}=ae();return async d=>{try{d.preventDefault(),await o(e,n,{action:"deleteStrategy",feature:s,payload:{id:a}}),i({title:"Changes added to the draft!",type:"success"}),await r()}catch(g){c(G(g))}}},ji=({projectId:e,featureId:s,environmentId:n,strategyId:a,isOpen:o,onClose:r})=>{const{isChangeRequestConfigured:i}=ce(e),{changeRequests:c}=Ks(e,a),l={changeRequests:c,projectId:e},d=yi({featureId:s,projectId:e,strategyId:a,environmentId:n}),g=mi({featureId:s,projectId:e,strategyId:a,environmentId:n});return i(n)?t.jsx(xi,{isOpen:o,onClose:()=>r(),onRemove:async f=>{await g(f),r()},scheduledChangeRequestsForStrategy:l}):t.jsx(hi,{isOpen:o,onClose:()=>r(),onRemove:d,scheduledChangeRequestsForStrategy:l})},bi=({projectId:e,environmentId:s,featureId:n,strategy:a})=>{const{refetchFeature:o}=W(e,n),{setStrategyDisabledState:r}=Ue(),{setToastData:i,setToastApiError:c}=ae(),l=d=>async()=>{try{await r(e,n,s,a.id,!d),i({title:`Strategy ${d?"enabled":"disabled"}`,type:"success"}),o()}catch(g){c(G(g))}};return{onDisable:l(!1),onEnable:l(!0)}},Si=({projectId:e,environmentId:s,featureId:n,strategy:a})=>{const{addChange:o}=Ee(),{refetch:r}=ve(e),{setToastData:i,setToastApiError:c}=ae(),l=d=>async()=>{try{await o(e,s,{action:"updateStrategy",feature:n,payload:{...a,disabled:!d}}),i({title:"Changes added to the draft!",type:"success"}),await r()}catch(g){c(G(g))}};return{onSuggestDisable:l(!1),onSuggestEnable:l(!0)}},vi=({isOpen:e,onClose:s,...n})=>{var y;const{projectId:a,environmentId:o}=n,{isChangeRequestConfigured:r}=ce(a),i=r(o),{onSuggestEnable:c,onSuggestDisable:l}=Si({...n}),{onEnable:d,onDisable:g}=bi({...n}),f=!!((y=n.strategy)!=null&&y.disabled),m=j=>{j.preventDefault(),i?f?c():l():f?d():g(),s()};return t.jsx(be,{title:i?`Add ${f?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${f?"enable":"disable"} this strategy?`,open:e,primaryButtonText:i?"Add to draft":`${f?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:m,onClose:()=>s(),children:t.jsx(C,{condition:i,show:t.jsx(ua,{environment:o}),elseShow:t.jsxs(he,{severity:"error",children:[f?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})},Ci=({projectId:e,strategy:s,featureId:n,environmentId:a})=>{const[o,r]=x.useState(null),[i,c]=x.useState(!1),[l,d]=x.useState(!1),g=!!o,f=S=>{r(S.currentTarget)},m=S=>{r(null),S.stopPropagation()},y=kt(pa,e,a),j=kt(ga,e,a);return t.jsxs(t.Fragment,{children:[t.jsx(Q,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t.jsx(ue,{title:"More actions",children:t.jsx(Qe,{onClick:f,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":ha,children:t.jsx(Lt,{sx:{width:32,height:32}})})})}),t.jsxs(et,{anchorEl:o,id:"actions-menu",open:g,onClose:m,onClick:m,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":fa,children:[t.jsx(ue,{title:s.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:t.jsxs(we,{disabled:!y,onClick:()=>c(!0),children:[t.jsx(Me,{children:s.disabled?t.jsx(xa,{}):t.jsx(ya,{})}),t.jsx(ke,{children:s.disabled?"Enable":"Disable"})]})}),t.jsx(ue,{title:"Remove strategy",arrow:!0,placement:"left",children:t.jsxs(we,{disabled:!j,onClick:()=>d(!0),"data-testid":ma,children:[t.jsx(Me,{children:t.jsx(Ns,{})}),t.jsx(ke,{children:"Remove"})]})})]}),t.jsx(vi,{isOpen:i,onClose:()=>c(!1),projectId:e,featureId:n,environmentId:a,strategy:s}),t.jsx(ji,{isOpen:l,onClose:()=>d(!1),projectId:e,featureId:n,environmentId:a,strategyId:s.id})]})},wi=({environmentId:e,strategy:s,onDragStart:n,onDragEnd:a,otherEnvironments:o,orderNumber:r,headerChildren:i})=>{const c=k("projectId"),l=k("featureId"),d=ja(c,l,e,s.id);return t.jsxs(gr,{strategy:s,onDragStart:n,onDragEnd:a,orderNumber:r,actions:t.jsxs(t.Fragment,{children:[i,t.jsx(C,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t.jsx(di,{environmentId:e,environments:o,strategy:s})}),t.jsx(je,{permission:ba,environmentId:e,projectId:c,component:ne,to:d,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${s.name}`,children:t.jsx(ze,{})}),t.jsx(Ci,{projectId:c,featureId:l,environmentId:e,strategy:s})]}),children:[t.jsx(Sa,{strategy:s}),s.variants&&s.variants.length>0&&(s.disabled?t.jsx(Q,{sx:{opacity:"0.5"},children:t.jsx(ts,{variants:s.variants})}):t.jsx(ts,{variants:s.variants}))]})},Ti=e=>fetch(e).then(qe("ChangeRequest")).then(s=>s.json()),yn=(e,s)=>{const{data:n,error:a,mutate:o}=Qs([],Fe(`api/admin/projects/${e}/change-requests/pending/${s}`),Ti);return{changeRequests:n,loading:!a&&!n,refetch:o,error:a}},Ei=(e,s,n,a)=>{const{user:o}=va(),{changeRequests:r}=yn(e,s),i=[],c=r==null?void 0:r.filter(l=>l.environment===n);return c==null||c.forEach(l=>{const d=l==null?void 0:l.features.find(f=>f.name===s),g=d==null?void 0:d.changes.find(f=>f.action==="updateStrategy"||f.action==="deleteStrategy"?f.payload.id===a:!1);if(g){const f=l.state==="Scheduled",m=!f&&l.createdBy.id===(o==null?void 0:o.id);f&&i.push({changeRequestId:l.id,change:g,isScheduledChange:f}),m&&i.push({changeRequestId:l.id,change:g,isScheduledChange:f})}}),i},mn=({scheduledChangeRequestIds:e})=>{const s=ct(),n=tt(s.breakpoints.down("sm")),a=k("projectId");return n?null:t.jsx(Q,{sx:{mr:1.5},children:t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e==null?void 0:e.map((o,r)=>t.jsxs(Wt,{to:`/projects/${a}/change-requests/${o}`,children:["Change request #",o]},`${a}-${r}`))}),children:t.jsx(Ne,{color:"warning",children:"Changes Scheduled"})})})},ms=({strategy:e,index:s,environmentName:n,otherEnvironments:a,isDragging:o,onDragStartRef:r,onDragOver:i,onDragEnd:c})=>{const l=k("projectId"),d=k("featureId"),g=x.useRef(null),f=Ei(l,d,n,e.id),{changeRequests:m}=Ks(l,e.id);return t.jsxs(Q,{ref:g,onDragOver:i(g,s),sx:{opacity:o?"0.5":"1"},children:[t.jsx(C,{condition:s>0,show:t.jsx(Ca,{text:"OR"})}),t.jsx(wi,{strategy:e,environmentId:n,otherEnvironments:a,onDragStart:r(g,s),onDragEnd:c,orderNumber:s+1,headerChildren:Ai(f,m)})]},e.id)},Ri=({change:e})=>{const s=ct();return tt(s.breakpoints.down("sm"))?null:t.jsxs(Q,{sx:{mr:1.5},children:[t.jsx(C,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t.jsx(Ne,{color:"warning",children:"Modified in draft"})}),t.jsx(C,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t.jsx(Ne,{color:"error",children:"Deleted in draft"})})]})},Ai=(e,s)=>{const n=[];if((e==null?void 0:e.length)===0&&(s==null?void 0:s.length)===0)return[];const a=e==null?void 0:e.find(({isScheduledChange:o})=>!o);return a&&n.push(t.jsx(Ri,{change:a.change},`draft-change#${a.change.id}`)),s&&s.length>0&&n.push(t.jsx(mn,{scheduledChangeRequestIds:s.map(o=>o.id)},"scheduled-changes")),n},Di=({environmentId:e,environments:s,onClick:n})=>{const a=k("projectId"),[o,r]=x.useState(null),i=!!o,{hasAccess:c}=x.useContext(Mt),l=s.some(d=>c($e,a,d));return t.jsxs("div",{children:[t.jsx(ue,{title:l?"":"(Access denied)",children:t.jsx("div",{children:t.jsx(Ie,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:d=>{r(d.currentTarget)},disabled:!l,variant:"outlined",children:"Copy from another environment"})})}),t.jsx(et,{id:"basic-menu",anchorEl:o,open:i,onClose:()=>{r(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:s.map(d=>{const g=c($e,a,d);return t.jsx(ue,{title:g?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(we,{onClick:()=>n(d),disabled:!g,children:[t.jsx(C,{condition:!g,show:t.jsx(Me,{children:t.jsx(Js,{fontSize:"small"})})}),t.jsxs(ke,{children:["Copy from ",d]})]})})},d)})})]})},ki=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),$i=({payload:e,fromEnvironment:s,environment:n})=>t.jsxs(ki,{children:[t.jsx(J,{children:t.jsx("strong",{children:"Copy: "})}),e==null?void 0:e.map(a=>t.jsxs(J,{children:[t.jsxs("strong",{children:[Ze((a==null?void 0:a.name)||"")," strategy"," "]})," "]})),t.jsxs(J,{children:["from ",s," to ",n]})]}),Fi=(e,s)=>{const n={};return s.parameters.forEach(a=>{n[a.name]=Ii(e,a)}),{name:s.name,constraints:[],parameters:n}},Ii=(e,s)=>s.name==="rollout"||s.name==="percentage"||s.type==="percentage"?"50":s.name==="stickiness"?"":s.name==="groupId"?e:s.type==="boolean"?"false":"",Pi=e=>{var o;const{uiConfig:s}=We(),n=((o=s.resourceLimits)==null?void 0:o.featureEnvironmentStrategies)||100,a=e>=n;return{limit:n,limitReached:a}},Bi=()=>{const[e,s]=x.useState(0),n=k("projectId"),a=k("featureId"),o=ss("environmentId"),r=ss("strategyName"),{strategy:i,defaultStrategyFallback:c}=tr(n,o),l=JSON.parse(wa().get("defaultStrategy")||"false"),{segments:d}=Ta(),g=(d||[]).filter(K=>{var fe;return(fe=i==null?void 0:i.segments)==null?void 0:fe.includes(K.id)}),[f,m]=x.useState({}),[y,j]=x.useState(l?g:[]),{strategyDefinition:S}=Ea(r),h=Ra(),{addStrategyToFeature:p,loading:w}=Ue(),{addChange:I}=Ee(),{setToastData:B,setToastApiError:O}=ae(),{uiConfig:$}=We(),{unleashUrl:P}=$,R=Re(),{feature:E,refetchFeature:_}=W(n,a),X=E==null?void 0:E.environments.find(K=>K.name===o),te=(X==null?void 0:X.strategies.length)||0,{limit:b,limitReached:T}=Pi(te),D=x.useRef(E),{isChangeRequestConfigured:v}=ce(n),{refetch:F}=ve(n),{trackEvent:L}=Se(),{data:V,staleDataNotification:z,forceRefreshCache:M}=Aa({unleashGetter:W,params:[n,a],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},E,{afterSubmitAction:_},La);x.useEffect(()=>{D.current.name===""&&E.name&&(M(E),D.current=E)},[E.name]),x.useEffect(()=>{var K;if(l){const fe=i||c;((K=fe.parameters)==null?void 0:K.groupId)===""&&a?m({...fe,parameters:{...fe.parameters,groupId:a}}):m(fe)}else S&&m(Fi(a,S))},[a,JSON.stringify(S),JSON.stringify(i),l]);const Z=async K=>{await p(n,a,o,K),B({title:"Strategy created",type:"success",confetti:!0})},ie=async K=>{await I(n,o,{action:"addStrategy",feature:a,payload:K}),B({title:"Strategy added to draft",type:"success",confetti:!0}),F()},A=Da(f,y),U=async()=>{L("strategyTitle",{props:{hasTitle:!!f.title,on:"create"}});try{v(o)?await ie(A):await Z(A),_(),R(_t(n,a))}catch(K){O(G(K))}};return!V||!V.project?null:t.jsxs(Xs,{modal:!0,description:ka,documentationLink:$a,documentationLinkLabel:Fa,disablePadding:!0,formatApiCode:()=>Li(n,a,o,A,P),children:[t.jsx(Ia,{projectId:n,feature:V,strategy:f,setStrategy:m,segments:y,setSegments:j,environmentId:o,onSubmit:U,loading:w,permission:$e,errors:h,isChangeRequest:v(o),tab:e,setTab:s,StrategyVariants:t.jsx(Pa,{strategy:f,setStrategy:m,environment:o,projectId:n,editable:!0}),Limit:t.jsx(Ba,{name:"strategies in this environment",shortName:"strategies",currentValue:te,limit:b}),disabled:T}),z]})},jn=(e,s,n,a,o=!1)=>{const r=new URLSearchParams({environmentId:n,strategyName:a,defaultStrategy:String(o)});return`/projects/${e}/features/${s}/strategies/create?${r}`},Li=(e,s,n,a,o)=>{if(!o)return"";const r=`${o}/api/admin/projects/${e}/features/${s}/environments/${n}/strategies`,i=JSON.stringify(a,void 0,2);return`curl --location --request POST '${r}' \\
|
|
2
2
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
3
|
--header 'Content-Type: application/json' \\
|
|
4
4
|
--data-raw '${i}'`},Oi=u("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),_i=u("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Mi=u(zt)(({theme:e})=>({fontWeight:e.fontWeight.bold})),zi=u(ne)(({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}})),jt=({projectId:e,featureId:s,environmentId:n,strategy:a,defaultStrategy:o})=>{const r=Zs(a.name),i=Ze(a.name),{trackEvent:c}=Se(),l=jn(e,s,n,a.name,o),d=()=>{c("strategy-add",{props:{buttonTitle:a.displayName||i}})};return t.jsxs(zi,{to:l,onClick:d,children:[t.jsx(Oi,{children:t.jsx(r,{})}),t.jsxs("div",{children:[t.jsx(Mi,{text:a.displayName||i,maxWidth:"200",maxLength:25}),t.jsx(_i,{children:a.description})]})]})},bt=u(J)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),Vi=({projectId:e,featureId:s,environmentId:n})=>{const{strategies:a}=Oa(),o=a.filter(c=>!c.deprecated&&!c.editable),r=a.filter(c=>!c.deprecated&&c.editable),i={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return t.jsxs(Vt,{dense:!0,children:[t.jsxs(t.Fragment,{children:[t.jsxs(bt,{color:"textSecondary",children:[n," environment default strategy"]}),t.jsx(_e,{children:t.jsx(jt,{projectId:e,featureId:s,environmentId:n,strategy:i,defaultStrategy:!0})},i.name)]}),t.jsx(bt,{color:"textSecondary",children:"Predefined strategy types"}),o.map(c=>t.jsx(_e,{children:t.jsx(jt,{projectId:e,featureId:s,environmentId:n,strategy:c})},c.name)),t.jsx(C,{condition:r.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(bt,{color:"textSecondary",children:"Custom strategies"}),r.map(c=>t.jsx(_e,{children:t.jsx(jt,{projectId:e,featureId:s,environmentId:n,strategy:c})},c.name))]})})]})},Ni=u("div")({flexShrink:0}),qi=u(Te)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),Ft=({label:e,projectId:s,featureId:n,environmentId:a,variant:o,size:r,matchWidth:i,disableReason:c})=>{const[l,d]=x.useState(),g=Re(),{trackEvent:f}=Se(),m=!!l,y=m?"FeatureStrategyMenuPopover":void 0,j=()=>{d(void 0)},S=w=>{f("strategy-add",{props:{buttonTitle:e}}),g(p)},h=w=>{d(w.currentTarget)},p=jn(s,n,a,"flexibleRollout",!0);return t.jsxs(Ni,{onClick:w=>w.stopPropagation(),children:[t.jsx(Te,{permission:$e,projectId:s,environmentId:a,onClick:S,"aria-labelledby":y,variant:o,size:r,sx:{minWidth:i?"282px":"auto"},disabled:!!c,tooltipProps:{title:c||void 0},children:e}),t.jsx(qi,{permission:$e,projectId:s,environmentId:a,onClick:h,"aria-labelledby":y,variant:"outlined",size:r,hideLockIcon:!0,disabled:!!c,tooltipProps:{title:c||"More strategies"},children:t.jsx(Lt,{sx:w=>({margin:w.spacing(.25,0)})})}),t.jsx(Vs,{id:y,open:m,anchorEl:l,onClose:j,onClick:j,PaperProps:{sx:w=>({paddingBottom:w.spacing(1)})},children:t.jsx(Vi,{projectId:s,featureId:n,environmentId:a})})]})},Wi=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Ui=u("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Hi=u("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),Yi=({projectId:e,featureId:s,environmentId:n})=>{const{addStrategyToFeature:a}=Ue(),{setToastData:o,setToastApiError:r}=ae(),{refetchFeature:i}=W(e,s),{refetchFeature:c}=hn(e,s),{feature:l}=W(e,s),d=l==null?void 0:l.environments.filter(w=>w.name!==n&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:g}=ce(e),{changeRequestDialogDetails:f,onChangeRequestAddStrategies:m,onChangeRequestAddStrategiesConfirm:y,onChangeRequestAddStrategyClose:j}=fn(e,s,"addStrategy"),S=(w=!1)=>{i(),c(),o({title:w?"Strategies created":"Strategy created",text:w?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},h=async w=>{var B;const I=((B=d==null?void 0:d.find(O=>O.name===w))==null?void 0:B.strategies)||[];if(g(n)){await m(n,I,w);return}try{await Promise.all(I.map(O=>{const{id:$,...P}={...O,environment:n};return a(e,s,n,P)})),S(!0)}catch(O){r(G(O))}},p=d&&d.length>0;return t.jsxs(t.Fragment,{children:[t.jsx(cn,{isOpen:f.isOpen,onClose:j,environment:f==null?void 0:f.environment,onConfirm:y,messageComponent:t.jsx($i,{fromEnvironment:f.fromEnvironment,payload:f.strategies})}),t.jsxs(Wi,{children:[t.jsx(Ui,{children:"You have not defined any strategies yet."}),t.jsxs(Hi,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t.jsx(ne,{to:"/admin/api",children:"API key configured"})," for this environment."]}),t.jsxs(Q,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t.jsx(Ft,{label:"Add your first strategy",projectId:e,featureId:s,environmentId:n,matchWidth:p}),t.jsx(C,{condition:p,show:t.jsx(Di,{environmentId:n,environments:d.map(w=>w.name),onClick:h})})]})]})]})},Gi=(e,s)=>{const n=[];let a=0;if(e.length<=a)return e;for(;a<e.length;)if(a===0){a+=s;const o=e.slice(0,a);n.push(o)}else{const o=e.slice(a,a+s);a+=s,n.push(o)}return n},Ji=(e,s,n)=>{const[a,o]=x.useState([[]]),[r,i]=x.useState(0);x.useEffect(()=>{const m=Gi(e,s);o(m)},[JSON.stringify(e),s]);const c=()=>{r<a.length-1&&i(f=>f+1)},l=()=>{r>0&&i(f=>f-1)},d=()=>{i(a.length-1)},g=()=>{i(0)};return{page:a[r]||[],pages:a,nextPage:c,prevPage:l,lastPage:d,firstPage:g,setPageIndex:i,pageIndex:r}},Ki=u("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Qi=u("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Xi=({featureEnvironment:e,isDisabled:s,otherEnvironments:n})=>{const a=k("projectId"),o=k("featureId"),{setStrategiesSortOrder:r}=Ue(),{addChange:i}=Ee(),{isChangeRequestConfigured:c}=ce(a),{refetch:l}=ve(a),{setToastData:d,setToastApiError:g}=ae(),{refetchFeature:f}=W(a,o),m=en("manyStrategiesPagination"),[y,j]=x.useState((e==null?void 0:e.strategies)||[]),{trackEvent:S}=Se(),[h,p]=x.useState(null);if(x.useEffect(()=>{j((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),x.useEffect(()=>{y.length>50&&S("many-strategies")},[]),!e)return null;const w=20,{page:I,pages:B,setPageIndex:O,pageIndex:$}=Ji(y,w),P=async b=>{try{await r(a,o,e.name,b),f(),d({title:"Order of strategies updated",type:"success"})}catch(T){g(G(T))}},R=async b=>{await i(a,e.name,{action:"reorderStrategy",feature:o,payload:b}),d({title:"Strategy execution order added to draft",type:"success",confetti:!0}),l()},E=async b=>{try{c(e.name)?await R(b):await P(b)}catch(T){g(G(T))}},_=(b,T)=>D=>{var v;p({id:y[T].id,index:T,height:((v=b.current)==null?void 0:v.offsetHeight)||0}),b!=null&&b.current&&(D.dataTransfer.effectAllowed="move",D.dataTransfer.setData("text/html",b.current.outerHTML),D.dataTransfer.setDragImage(b.current,20,20))},X=b=>(T,D)=>v=>{if(h===null||T.current===null||h.index===D||b===h.id)return;const{top:F,bottom:L}=T.current.getBoundingClientRect(),V=v.clientY-F<h.height,z=L-v.clientY<h.height,M=h.index>D;if(V&&M||z&&!M){const Z=[...y],ie=Z.splice(h.index,1)[0];Z.splice(D,0,ie),j(Z),p({...h,index:D})}},te=()=>{p(null),E(y.map((b,T)=>({id:b.id,sortOrder:T})))};return t.jsx(Ki,{children:t.jsxs(Qi,{children:[t.jsx(C,{condition:y.length>0&&s,show:()=>t.jsx(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t.jsx(C,{condition:y.length>0,show:t.jsx(C,{condition:y.length<50||!m,show:t.jsx(t.Fragment,{children:y.map((b,T)=>t.jsx(ms,{strategy:b,index:T,environmentName:e.name,otherEnvironments:n,isDragging:(h==null?void 0:h.id)===b.id,onDragStartRef:_,onDragOver:X(b.id),onDragEnd:te},b.id))}),elseShow:t.jsxs(t.Fragment,{children:[t.jsx(he,{severity:"error",children:"We noticed you're using a high number of activation strategies. To ensure a more targeted approach, consider leveraging constraints or segments."}),t.jsx("br",{}),I.map((b,T)=>t.jsx(ms,{strategy:b,index:T+$*w,environmentName:e.name,otherEnvironments:n,isDragging:!1,onDragStartRef:()=>{},onDragOver:()=>{},onDragEnd:()=>{}},b.id)),t.jsx("br",{}),t.jsx(Dr,{count:B.length,shape:"rounded",page:$+1,onChange:(b,T)=>O(T-1)})]})}),elseShow:t.jsx(Yi,{projectId:a,featureId:o,environmentId:e.name})})]})})},bn=(e,s)=>e===0?0:Math.round(s/e*100),ot=({value:e,threshold:s=1e6,precision:n=2})=>{let a,o=!1;e<s?a=e.toLocaleString():(a=_a(e,{precision:n}),o=!0);const r=t.jsx("span",{"data-testid":Ma,children:a});return t.jsx(C,{condition:o,show:t.jsx(ue,{title:e.toLocaleString(),arrow:!0,children:r}),elseShow:r})},Zi=e=>e>48?`${Math.floor(e/24)} days (UTC)`:`${e} hours (local time)`,St=u("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),vt=u("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),Ct=u("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),wt=u("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.divider,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),Sn=({totalYes:e,totalNo:s,hoursBack:n,statsSectionId:a,tableSectionId:o})=>{const r=n===1?"in the last hour":`in the last ${Zi(n)}`;return t.jsxs(Ce,{container:!0,spacing:2,id:a,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t.jsx(Ce,{item:!0,xs:12,sm:4,children:t.jsxs(St,{children:[t.jsx(vt,{children:"Exposure"}),t.jsx(Ct,{children:t.jsx(ot,{value:e})}),t.jsxs(wt,{children:["Total exposure of the feature in the environment"," ",r,"."]})]})}),t.jsx(Ce,{item:!0,xs:12,sm:4,children:t.jsxs(St,{children:[t.jsx(vt,{children:"Exposure %"}),t.jsxs(Ct,{children:[bn(e+s,e),"%"]}),t.jsxs(wt,{children:["% total exposure of the feature in the environment"," ",r,"."]})]})}),t.jsx(Ce,{item:!0,xs:12,sm:4,children:t.jsxs(St,{children:[t.jsx(vt,{children:"Requests"}),t.jsx(Ct,{children:t.jsx(ot,{value:e+s})}),t.jsxs(wt,{children:["Total requests for the feature in the environment"," ",r,"."]})]})})]})},ec=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.divider}})),tc=u("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.envAccordion.expanded,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),sc=({children:e})=>t.jsx(ec,{children:t.jsx(tc,{children:e})}),nc=({environmentMetric:e})=>e?t.jsxs(t.Fragment,{children:[t.jsx(sc,{children:"Feature flag exposure"}),t.jsx("div",{children:t.jsx(Sn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,js=u("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),bs=u("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ss=u("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),vs=u("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),ac=u(za)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),oc=u("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),rc=({environmentMetric:e,disabled:s=!1})=>{const n=Va();if(!e)return null;const a=e.yes+e.no,o=bn(a,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?t.jsxs(js,{children:[t.jsxs(bs,{children:[t.jsxs(Ss,{style:{color:s?n.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),t.jsxs(vs,{style:{color:s?n.palette.text.secondary:n.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t.jsx("b",{children:"0 times"})," and exposed",t.jsx("b",{children:" 0 times"})," in the last hour"]})]}),t.jsx(ac,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):t.jsxs(js,{children:[t.jsxs(bs,{children:[t.jsxs(Ss,{children:[o,"%"]}),t.jsxs(vs,{children:["The feature has been requested"," ",t.jsxs("b",{children:[t.jsx(ot,{value:a})," times"]})," ","and exposed"," ",t.jsxs("b",{children:[t.jsx(ot,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t.jsx(oc,{"data-loading":!0,children:t.jsx(Na,{percentage:o,size:"3rem"})})]})},Tt=({strategy:e})=>{const s=Zs(e.name);return t.jsx(ue,{title:Ze(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t.jsx(ic,{children:t.jsx(s,{})})})},ic=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.action.disabled,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),Cs=u("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Et=u("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),cc=u("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),st=5,lc=({strategies:e})=>e!=null&&e.length?e.length>st+1?t.jsxs(Cs,{"aria-label":"Feature strategies",children:[e.slice(0,st).map(s=>t.jsx(Et,{children:t.jsx(Tt,{strategy:s})},s.id)),t.jsxs(Xe,{tooltip:e.slice(st).map(s=>t.jsx(Et,{children:t.jsxs(cc,{children:[t.jsx(Tt,{strategy:s})," ",Ze(s.name)+(s.title?` - ${s.title}`:"")]})},s.id)),children:["(+",e.length-st,")"]})]}):t.jsx(Cs,{"aria-label":"Feature strategies",children:e.map(s=>t.jsx(Et,{children:t.jsx(Tt,{strategy:s})},s.id))}):null,vn=()=>{const{value:e,setValue:s}=qa("global:v1",{});return{value:{...e,hiddenEnvironments:Array.from(e.hiddenEnvironments||[])},setValue:s}},dc=u("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:s})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:s?e.palette.background.paper:e.palette.envAccordion.disabled})),uc=u(Wa)({boxShadow:"none",background:"none"}),pc=u(Ua)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),gc=u(Ha,{shouldForwardProp:e=>e!=="enabled"})(({theme:e})=>({padding:e.spacing(3),background:e.palette.envAccordion.expanded,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,boxShadow:e.boxShadows.accordionFooter,[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),hc=u(Xi)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),fc=u("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:s})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:s?e.palette.text.primary:e.palette.text.secondary})),xc=u("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),yc=u(Ya)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),mc=u(zt)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),jc=u("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),bc=({env:e})=>{var d;const s=k("projectId"),n=k("featureId"),{metrics:a}=si(s,n),{feature:o}=W(s,n),{value:r}=vn(),c=ai(o==null?void 0:o.environments,a).find(g=>g.environment===e.name),l=o==null?void 0:o.environments.find(g=>g.name===e.name);return t.jsx(C,{condition:!new Set(r.hiddenEnvironments).has(e.name),show:t.jsx(dc,{enabled:e.enabled,children:t.jsxs(uc,{TransitionProps:{mountOnEnter:!0},"data-testid":`${Ga}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[t.jsxs(pc,{expandIcon:t.jsx(Ja,{titleAccess:"Toggle"}),children:[t.jsxs(fc,{"data-loading":!0,enabled:e.enabled,children:[t.jsxs(xc,{children:[t.jsx(yc,{enabled:e.enabled}),t.jsx("div",{children:t.jsx(mc,{text:e.name,maxWidth:"100",maxLength:15})}),t.jsx(C,{condition:!e.enabled,show:t.jsx(Ne,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),t.jsxs(jc,{children:[t.jsx(Ft,{label:"Add strategy",projectId:s,featureId:n,environmentId:e.name,variant:"outlined",size:"small"}),t.jsx(lc,{strategies:l==null?void 0:l.strategies})]})]}),t.jsx(rc,{environmentMetric:c,disabled:!e.enabled})]}),t.jsxs(gc,{enabled:e.enabled,children:[t.jsx(hc,{featureEnvironment:l,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t.jsx(C,{condition:(((d=l==null?void 0:l.strategies)==null?void 0:d.length)||0)>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Q,{sx:{display:"flex",justifyContent:"center",py:1},children:t.jsx(Ft,{label:"Add strategy",projectId:s,featureId:n,environmentId:e.name})}),t.jsx(nc,{environmentMetric:c})]})})]})]})})})},Sc=()=>{const e=k("projectId"),s=k("featureId"),{feature:n}=W(e,s);if(!n)return null;const{environments:a}=n;return t.jsx(t.Fragment,{children:a==null?void 0:a.map(o=>t.jsx(bc,{env:o},o.name))})},vc=u(Qe,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:s})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:s?e.palette.action.active:e.palette.action.focus,"&:hover":{color:e.palette.action.active}})),Cc=({environment:e,hiddenEnvironments:s,setHiddenEnvironments:n})=>{const a=()=>{n(e.name)};return t.jsx(vc,{onClick:a,visibilityOff:s.has(e.name),children:t.jsx(C,{condition:s.has(e.name),show:t.jsx(Ka,{}),elseShow:t.jsx(Qa,{})})})},wc=u("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Tc=u("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Ec=({environment:e,callback:s,children:n,hiddenEnvironments:a,setHiddenEnvironments:o})=>{const r=k("projectId"),i=k("featureId"),{feature:c,refetchFeature:l}=W(r,i),{isChangeRequestConfigured:d}=ce(r),g=t.jsxs(t.Fragment,{children:[" ",t.jsxs("span",{"data-loading":!0,children:[e.enabled?"enabled":"disabled"," in"]})," ",t.jsx(zt,{text:e.name,maxWidth:"120",maxLength:15})]}),{onToggle:f,modals:m}=sr(r),y=(j,S)=>f(j,{projectId:r,featureId:i,environmentName:e.name,environmentType:e.type,hasStrategies:e.strategies.length>0,hasEnabledStrategies:e.strategies.some(h=>!h.disabled),isChangeRequestEnabled:d(e.name),onRollback:S,onSuccess:()=>{s&&s(),l()}});return t.jsxs(wc,{children:[t.jsxs(Tc,{children:[t.jsx(nr,{featureId:c.name,projectId:r,environmentName:e.name,onToggle:y,value:e.enabled}),n??g]}),t.jsx(Cc,{environment:e,hiddenEnvironments:a,setHiddenEnvironments:o}),m]})},Rc=u("div")(({theme:e})=>({padding:e.spacing(3)})),Ac=u("div")(()=>({display:"flex",flexDirection:"column"})),Dc=u("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),kc=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),ws=u("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),$c=u(Nt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),Fc=({feature:e,header:s,hiddenEnvironments:n,setHiddenEnvironments:a})=>{const o=e.environments.some(r=>{var i;return r.enabled&&((i=r.variants)==null?void 0:i.length)});return t.jsxs(Rc,{"data-testid":"feature-flag-status",children:[s,e.environments.map(r=>{const i=r.strategies.length===1?"1 strategy":`${r.strategies.length} strategies`,c=r.variants??[],l=c.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(ws,{}),t.jsx(ue,{title:"View variants",arrow:!0,describeChild:!0,children:t.jsx($c,{component:ne,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:c.length===1?"1 variant":`${c.length} variants`})})]}),d=r.enabled&&c.length===0&&o;return t.jsx(Ec,{environment:r,hiddenEnvironments:n,setHiddenEnvironments:a,children:t.jsxs(Ac,{children:[t.jsx(Dc,{children:r.name}),t.jsxs(kc,{children:[i,l,t.jsx(C,{condition:d,show:t.jsxs(t.Fragment,{children:[t.jsx(ws,{}),t.jsx(ar,{})]})})]})]})},r.name)})]})},Cn=(e,s={})=>{const n=async()=>{const d=Fe(`api/admin/features/${e}/tags`);return(await fetch(d,{method:"GET"}).then(qe("Tags"))).json()},a=`api/admin/features/${e}/tags`,{data:o,error:r}=Ws(!!e,{tags:[]},a,n,s),[i,c]=x.useState(!r&&!o),l=()=>{Ot(a)};return x.useEffect(()=>{c(!r&&!o)},[o,r]),{tags:(o==null?void 0:o.tags)||[],error:r,loading:i,refetch:l}},Ic=u("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),Rt=e=>e.map(s=>({title:s.value})),Ts=(e,s)=>e.map(n=>({value:n.title,type:s})),wn=({open:e,setOpen:s})=>{const{tagTypes:n}=Xa(),a=k("featureId"),{createTag:o}=or(),{updateFeatureTags:r,loading:i}=lt(),{tags:c,refetch:l,loading:d}=Cn(a),{setToastData:g}=ae(),f=n&&n.length>0?n[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[m,y]=x.useState(f),j=i||d,[S,h]=x.useState(0),{trackEvent:p}=Se(),[w,I]=x.useState(Rt(c.filter(v=>v.type===m.name))),{tags:B,refetch:O}=rr(m.name),$=x.useMemo(()=>Rt(B),[B]);x.useEffect(()=>{c&&m&&I(Rt(c.filter(v=>v.type===m.name)))},[JSON.stringify(c),m]);const P=()=>{s(!1),I([])};function R(v,F){const L=v.filter(z=>z.type===m.name).filter(z=>!F.find(M=>z.value===M.value&&z.type===M.type)),V=F.filter(z=>z.type===m.name).filter(z=>!v.find(M=>z.value===M.value&&z.type===M.type));return h(L.length+V.length),{added:L,removed:V}}const E=v=>v.filter(F=>!F.title.startsWith("Create")),_=async(v,F)=>{try{await r(a,{addedTags:v,removedTags:F}),await l()}catch(L){const V=G(L);g({type:"error",title:"Failed to add tag",text:V,confetti:!1})}},X=(v,F)=>{let L="We successfully";return v>0&&(L=L.concat(` added ${v} new tag${v>1?"s":""}`)),v>0&&F>0&&(L=L.concat(" and ")),F>0&&(L=L.concat(` removed ${F} tag${F>1?"s":""}`)),L},te=async v=>{v.preventDefault();const F=Ts(E(w),m.name),{added:L,removed:V}=R(F,c);S>0&&(await _(L,V),S>1&&p("suggest_tags",{props:{eventType:"multiple_tags_added"}}),S>0&&g({type:"success",title:`Updated tag${L.length>1?"s":""} to flag`,text:X(L.length,V.length),confetti:!0})),h(0),I([]),s(!1)},b=(v,F)=>{F!=null&&typeof F!="string"&&(v.preventDefault(),y(F),I([]),h(0))},T=(v,F,L)=>{const V=Za(F);L==="selectOption"&&F.forEach((M,Z)=>{if(typeof M!="string"&&M.inputValue&&M.inputValue!==""){const ie={value:M.inputValue,type:m.name};o(ie).then(()=>{p("suggest_tags",{props:{eventType:"tag_created"}}),O()}),M.title=M.inputValue,M.inputValue="",V[Z]=M}});const z=Ts(E(V),m.name);R(z,c),I(V)},D="add-tag-form";return t.jsx(be,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update feature flag tags",onClick:te,disabledPrimaryButton:j||S===0,onClose:P,formId:D,children:t.jsxs(t.Fragment,{children:[t.jsx(J,{paragraph:!0,sx:{marginBottom:v=>v.spacing(2.5)},children:"Tags allow you to group features together"}),t.jsx("form",{id:D,onSubmit:te,children:t.jsxs(Ic,{children:[t.jsx(ir,{options:n,value:m,onChange:b}),t.jsx(cr,{options:$,existingTags:c,tagType:m,selectedOptions:w,onChange:T})]})})]})})},Pc=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Bc=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Lc=u(tn)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Oc=u(dt)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),_c=u(Ie)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Mc=({feature:e,header:s})=>{const{tags:n,refetch:a}=Cn(e.name),{deleteTagFromFeature:o}=lt(),[r,i]=x.useState(!1),[c,l]=x.useState(!1),[d,g]=x.useState(),{setToastData:f,setToastApiError:m}=ae(),{hasAccess:y}=x.useContext(Mt),j=y(Ve,e.project),S=async()=>{if(d)try{await o(e.name,d.type,d.value),a(),f({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(h){m(G(h))}};return t.jsxs(Pc,{children:[s,t.jsx(Bc,{children:n.map(h=>{const p=`${h.type}:${h.value}`;return t.jsx(Lc,{label:p,deleteIcon:t.jsx(eo,{titleAccess:"Remove"}),onDelete:j?()=>{l(!0),g(h)}:void 0},p)})}),t.jsx(C,{condition:j,show:t.jsxs(t.Fragment,{children:[t.jsx(C,{condition:n.length>0,show:t.jsx(Oc,{})}),t.jsx(_c,{"data-loading":!0,variant:"outlined",startIcon:t.jsx(to,{}),onClick:()=>i(!0),children:"Add new tag"})]})}),t.jsx(wn,{open:r,setOpen:i}),t.jsxs(be,{open:c,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{l(!1),g(void 0)},onClick:()=>{l(!1),S(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",t.jsxs("strong",{children:[d==null?void 0:d.type,":",d==null?void 0:d.value]})]})]})},zc=u(Q)(({theme:e})=>({top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),Es=u("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),Vc=({hiddenEnvironments:e,setHiddenEnvironments:s})=>{var i;const n=k("projectId"),a=k("featureId"),{feature:o}=W(n,a),r=((i=o.environments)==null?void 0:i.length)<=3;return t.jsxs(zc,{as:r?so:Q,children:[t.jsx(Fc,{header:t.jsxs(Es,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:c})=>c).length,")",t.jsx(no,{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:s}),t.jsx(dt,{}),t.jsx(Mc,{header:t.jsx(Es,{"data-loading":!0,children:"Tags for this feature flag"}),feature:o})]})},Nc=()=>{const{trackEvent:e}=Se(),{value:s,setValue:n}=vn(),[a,o]=x.useState(new Set(s.hiddenEnvironments));return{hiddenEnvironments:a,setHiddenEnvironments:i=>{n(c=>{const l=new Set(Array.from(c.hiddenEnvironments||[]));return l.has(i)?(l.delete(i),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(l.add(i),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(l),{...s,hiddenEnvironments:[...l]}})}}},qc=u("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Wc=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),Uc=()=>{const e=Re(),s=k("projectId"),n=k("featureId"),a=_t(s,n),{hiddenEnvironments:o,setHiddenEnvironments:r}=Nc(),i=()=>e(a);sn(n);const{setLastViewed:c}=ao();return x.useEffect(()=>{c({featureId:n,projectId:s})},[n]),t.jsxs(qc,{children:[t.jsxs("div",{children:[t.jsx(ti,{}),t.jsx(Vc,{hiddenEnvironments:o,setHiddenEnvironments:r})]}),t.jsx(Wc,{children:t.jsx(Sc,{})}),t.jsxs(nn,{children:[t.jsx(Ae,{path:"strategies/create",element:t.jsx($t,{label:"Create feature strategy",onClose:i,open:!0,children:t.jsx(Bi,{})})}),t.jsx(Ae,{path:"strategies/edit",element:t.jsx($t,{label:"Edit feature strategy",onClose:i,open:!0,children:t.jsx(oo,{})})})]})]})},Hc=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-3.5),marginBottom:e.spacing(2),backgroundColor:e.palette.background.default,paddingTop:e.spacing(2),paddingBottom:e.spacing(2),position:"sticky",top:0,zIndex:2})),Yc=u(an,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.neutral.border:e.palette.primary.main})),Gc=u("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Jc=u("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Kc=u(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Qc=u(he)(({theme:e})=>({marginTop:e.spacing(4)})),Xc=u("div")({display:"flex",flexDirection:"column"}),Zc=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Rs=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),el=u(dt)(({theme:e})=>({margin:e.spacing(4,0)})),tl=u(ro)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),sl=u("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),nl=u(Ie)(({theme:e})=>({marginLeft:e.spacing(3)})),al=x.memo(io),ol=({environment:e,open:s,setOpen:n,getApiPayload:a,getCrPayload:o,onConfirm:r})=>{const i=k("projectId"),c=k("featureId"),{uiConfig:l}=We(),{context:d}=co(),{defaultStickiness:g,loading:f}=lo(i),{isChangeRequestConfigured:m}=ce(i),{data:y}=ve(i),{changeRequestInReviewOrApproved:j,alert:S}=po(y),h=(e==null?void 0:e.variants)||[],[p,w]=x.useState([]),[I,B]=x.useState();x.useEffect(()=>{f||w(h.length?h.map(A=>({...A,isValid:!0,new:!1,id:ht()})):[{name:"",weightType:ns.VARIABLE,weight:0,overrides:[],stickiness:(p==null?void 0:p.length)>0?p[0].stickiness:g,new:!0,isValid:!1,id:ht()}])},[s,f]);const O=(A,U)=>{w(pe=>as(pe.map(K=>K.id===U?A:K),1e3))},$=()=>{const A=ht();w(U=>[...U,{name:"",weightType:ns.VARIABLE,weight:0,overrides:[],stickiness:(U==null?void 0:U.length)>0?U[0].stickiness:g,new:!0,isValid:!1,id:A}]),B(A)};x.useEffect(()=>{if(I){const A=document.getElementById(`variant-name-input-${I}`);A==null||A.scrollIntoView({behavior:"smooth",block:"center"}),A==null||A.focus({preventScroll:!0}),B(void 0)}},[I]);const P=p.map(({new:A,isValid:U,id:pe,...K})=>K),R=a(h,P),E=o(P),_=async A=>{A.preventDefault(),r(P)},X=()=>D?`curl --location --request POST '${l.unleashUrl}/api/admin/projects/${i}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
@@ -7,4 +7,4 @@ import{aA as Ls,aB as Os,_ as It,aC as $n,a as re,aD as it,j as t,s as u,aE as F
|
|
|
7
7
|
--data-raw '${JSON.stringify(E,void 0,2)}'`:`curl --location --request PATCH '${l.unleashUrl}/api/admin/projects/${i}/features/${c}/environments/${e==null?void 0:e.name}/variants' \\
|
|
8
8
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
9
9
|
--header 'Content-Type: application/json' \\
|
|
10
|
-
--data-raw '${JSON.stringify(R.patch,void 0,2)}'`,te=p.every(({isValid:A})=>A),b=j((e==null?void 0:e.name)||""),T=b?"Add to existing change request":"Add change to draft",D=m((e==null?void 0:e.name)||""),v=x.useMemo(()=>{var A;return f?"":((A=P[0])==null?void 0:A.stickiness)||g},[f,g,JSON.stringify(P[0]??{})]),F=x.useMemo(()=>["default",...d.filter(A=>A.stickiness).map(A=>A.name)],[d]),L=F.map(A=>({key:A,label:A}));F.includes(v)||L.push({key:v,label:v});const V=async A=>{w(U=>U.map(pe=>({...pe,stickiness:A})))},z=A=>{V(A)},[M,Z]=x.useState();x.useEffect(()=>{Z(void 0),R.error&&Z(R.error)},[R.error]);const ie=()=>{V(g),n(!1)};return f||v===""?t.jsx(uo,{}):t.jsx($t,{open:s,onClose:ie,label:"",children:t.jsxs(Xs,{modal:!0,title:"",description:"Variants allow you to return a variant object if the feature flag is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature flag variants documentation",formatApiCode:X,loading:!s,children:[t.jsxs(Hc,{children:[t.jsxs("div",{children:[t.jsx(Yc,{deprecated:!(e!=null&&e.enabled)}),t.jsx(Gc,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t.jsx(Te,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:$,variant:"outlined",permission:Le,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),t.jsxs(Jc,{onSubmit:_,children:[t.jsx(C,{condition:b,show:S,elseShow:t.jsx(C,{condition:!!D,show:t.jsxs(Kc,{severity:"info",children:[t.jsx("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t.jsx(Xc,{children:p.map(A=>t.jsx(al,{variant:A,variants:p,updateVariant:U=>O(U,A.id),removeVariant:()=>w(U=>as(U.filter(pe=>pe.id!==A.id),1e3)),error:R.error},A.id))}),t.jsx(Te,{onClick:$,variant:"outlined",permission:Le,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"}),t.jsx(el,{}),t.jsx(C,{condition:p.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Zc,{children:t.jsx("p",{children:"Stickiness"})}),t.jsxs(Rs,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Nt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t.jsx("div",{children:t.jsx(tl,{value:v,label:"",editable:!0,onChange:A=>z(A.target.value)})})]}),elseShow:t.jsx(Rs,{children:"This environment has no variants. Get started by adding a variant."})}),t.jsxs(Qc,{severity:"error",hidden:!M,children:[t.jsx("strong",{children:"Error: "}),M]}),t.jsxs(sl,{children:[t.jsx(Ie,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!te,children:D?T:"Save variants"}),t.jsx(nl,{onClick:ie,children:"Cancel"})]})]})]})})},rl=e=>fetch(e).then(qe("ChangeRequest")).then(s=>s.json()),il=(e,s)=>{const{data:n,error:a,mutate:o}=Qs([],Fe(`api/admin/projects/${e}/change-requests/scheduled?variantForFlag=${s}`),rl);return{changeRequests:n,loading:!a&&!n,refetch:o,error:a}},cl=(e,s,n)=>{const{changeRequests:a}=il(e,s),o=a==null?void 0:a.filter(r=>r.environment===n);return o?o.map(r=>r.id):[]},ll=u("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),dl=u("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),ul=u(an,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.neutral.border:e.palette.primary.main})),pl=u("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),gl=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),hl=u("div")(({theme:e})=>({margin:e.spacing(3,0)})),fl=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),xl=({environment:e,searchValue:s,children:n})=>{var l;const a=k("projectId"),o=k("featureId"),r=cl(a,o,e.name),i=e.variants??[],c=((l=i[0])==null?void 0:l.stickiness)||"default";return t.jsxs(ll,{children:[t.jsxs(dl,{children:[t.jsxs("div",{children:[t.jsx(ul,{deprecated:!e.enabled}),t.jsx(pl,{deprecated:!e.enabled,children:e.name}),t.jsx(C,{condition:r.length>0,show:t.jsx(go,{sx:{ml:2},children:t.jsx(mn,{scheduledChangeRequestIds:r})})})]}),n]}),t.jsx(C,{condition:i.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(hl,{children:t.jsx(ho,{variants:i,searchValue:s})}),t.jsx(C,{condition:i.length>1,show:t.jsxs(t.Fragment,{children:[t.jsxs(fl,{children:[t.jsx("p",{children:"Stickiness:"}),t.jsx(Ne,{children:c})]}),t.jsxs(gl,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Nt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},yl=u(ke)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ml=({environment:e,permission:s,projectId:n,environmentId:a,onCopyVariantsFrom:o,otherEnvsWithVariants:r})=>{const[i,c]=x.useState(null),l=!!i,d=e.variants??[];return t.jsx(C,{condition:r.length>0&&d.length===0,show:t.jsxs(t.Fragment,{children:[t.jsx(Te,{onClick:g=>{c(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",permission:s,projectId:n,environmentId:a,children:"Copy variants from"}),t.jsx(et,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:r.map(g=>t.jsx(we,{onClick:()=>o(g,e),children:t.jsx(yl,{children:`Copy from ${g.name}`})},g.name))})]})})},jl=({permission:e,projectId:s,environment:n,checked:a,onClick:o,...r})=>{const i=kt(e,s,n);return t.jsxs(we,{disabled:!i,onClick:o,...r,children:[t.jsx(zs,{checked:a}),n]})},bl=u(et)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Sl=u("div")(({theme:e})=>({margin:e.spacing(1,2)})),vl=u(Ie)(({theme:e})=>({marginTop:e.spacing(2)})),Cl=({current:e,environments:s,permission:n,projectId:a,onSubmit:o})=>{var S;const[r,i]=x.useState(null),c=!!r,[l,d]=x.useState([]),g=h=>{d(p=>[...p,h])},f=h=>{d(p=>p.filter(({name:w})=>w!==h.name))},m=h=>{l.includes(h)?f(h):g(h)},y=()=>{d([]),i(null)},j=((S=s.find(h=>h.name===e))==null?void 0:S.variants)??[];return t.jsx(C,{condition:j.length>0&&s.length>1,show:t.jsxs(t.Fragment,{children:[t.jsx(Ie,{onClick:h=>{i(h.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Copy to environment"}),t.jsxs(bl,{anchorEl:r,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[s.filter(h=>h.name!==e).map(h=>t.jsx(jl,{projectId:a,permission:n,environment:h.name,checked:l.includes(h),onClick:()=>m(h)},h.name)),t.jsxs(Sl,{children:[t.jsx(dt,{}),t.jsxs(vl,{variant:"outlined",onClick:()=>{o(l),y()},disabled:l.length===0,children:["Push to selected (",l.length,")"]})]})]})]})})},wl=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Tl=()=>{const{setToastData:e,setToastApiError:s}=ae(),n=ct(),a=tt(n.breakpoints.down("md")),o=k("projectId"),r=k("featureId"),{feature:i,refetchFeature:c,loading:l}=W(o,r),{patchFeatureEnvironmentVariants:d,overrideVariantsInEnvironments:g}=lt(),{refetch:f}=ve(o),{addChange:m}=Ee(),{isChangeRequestConfigured:y}=ce(o),[j,S]=x.useState(""),[h,p]=x.useState(),[w,I]=x.useState(!1),B=x.useMemo(()=>{var b;return((b=i==null?void 0:i.environments)==null?void 0:b.map(T=>({...T,crEnabled:y(T.name)})))||[]},[i.environments]),O=(b,T)=>mo(b,T),$=(b,T)=>{try{const D=yo(T,1e3);return{patch:O(b,D)}}catch(D){return{patch:[],error:G(D)}}},P=b=>({feature:r,action:"patchVariant",payload:{variants:b}}),R=async(b,T)=>{if(b.crEnabled)await m(o,b.name,P(T)),f();else{const D=b.variants??[],{patch:v,error:F}=$(D,T);if(v.length===0)return;if(F){e({type:"error",title:F});return}await d(o,r,b.name,v)}c()},E=async(b,T)=>{try{const D=T.filter(({crEnabled:z})=>z),v=T.filter(({crEnabled:z})=>!z);D.length&&await Promise.all(D.map(z=>m(o,z.name,P(b)))),v.length&&await g(o,r,b,v.map(({name:z})=>z)),f(),c();const F=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",L=D.length?`Variants push added to ${D.length===1?`${D[0].name} draft`:`${D.length} drafts`}`:"",V=`${F}${F&&L?". ":""}${L}`;e({title:V,type:"success"})}catch(D){s(G(D))}},_=b=>{p(b),I(!0)},X=async b=>{if(h)try{await R(h,b),I(!1),e({title:h.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(T){s(G(T))}},te=async(b,T)=>{try{const D=b.variants??[];await R(T,D),e({title:T.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(D){s(G(D))}};return t.jsxs(qt,{isLoading:l,header:t.jsx(fo,{title:"Variants",actions:t.jsx(C,{condition:!a,show:t.jsx(t.Fragment,{children:t.jsx(os,{initialValue:j,onChange:S})})}),children:t.jsx(C,{condition:a,show:t.jsx(os,{initialValue:j,onChange:S})})}),children:[t.jsx(xo,{}),B.map(b=>{var D;const T=B.filter(({name:v,variants:F})=>v!==b.name&&(F==null?void 0:F.length));return t.jsx(xl,{environment:b,searchValue:j,children:t.jsxs(wl,{children:[t.jsx(Cl,{current:b.name,environments:B,permission:Le,projectId:o,onSubmit:v=>E(b.variants??[],v)}),t.jsx(ml,{environment:b,permission:Le,projectId:o,environmentId:b.name,onCopyVariantsFrom:te,otherEnvsWithVariants:T}),t.jsx(C,{condition:!!((D=b.variants)!=null&&D.length),show:t.jsx(je,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>_(b),permission:Le,projectId:o,environmentId:b.name,tooltipProps:{title:"Edit variants"},children:t.jsx(ze,{})}),elseShow:t.jsx(Te,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>_(b),variant:"outlined",permission:Le,projectId:o,environmentId:b.name,children:"Add variant"})})]})},b.name)}),t.jsx(ol,{environment:h,open:w,setOpen:I,getApiPayload:$,getCrPayload:P,onConfirm:X})]})},El=Fe("api/admin/client-metrics/features"),Tn=(e,s)=>{const n=Fe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${s}`),{data:a,error:o}=Ys(n,()=>Rl(n)),r=x.useCallback(()=>{Ot(El).catch(console.warn)},[]);return{featureMetrics:a==null?void 0:a.data,loading:!o&&!a,refetchFeatureMetrics:r,error:o}},Rl=e=>fetch(e).then(qe("Features")).then(s=>s.json()).then(),Al=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),rt=48,Dl=({hoursBack:e,setHoursBack:s})=>{const{trackEvent:n}=Se(),a=c=>{s(Number.parseInt(c)),n("feature-metrics",{props:{eventType:"change-period",hoursBack:c}})},{isEnterprise:o}=We(),r=o()?[...As,...kl]:As,i=r.map(c=>Number(c.key)).includes(e)?e:rt;return x.useEffect(()=>{e!==i&&s(i)},[e]),t.jsxs("div",{children:[t.jsx(Al,{children:"Period"}),t.jsx(Pt,{name:"feature-metrics-period",id:"feature-metrics-period",options:r,value:String(i),onChange:a,fullWidth:!0})]})},As=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:"48",label:"Last 48 hours"}],kl=[{key:`${7*24}`,label:"Last 7 days"},{key:`${30*24}`,label:"Last 30 days"},{key:`${90*24}`,label:"Last 90 days"}],$l=({value:e,timeZone:s})=>{const{locationSettings:n}=Us(),a=e?e instanceof Date?rs(e,n.locale,s):rs(Hs(e),n.locale,s):void 0;return t.jsx(at,{lineClamp:1,children:a})};var Ut={},Fl=bo;Object.defineProperty(Ut,"__esModule",{value:!0});var En=Ut.default=void 0,Il=Fl(jo()),Pl=t,Bl=(0,Il.default)((0,Pl.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment");En=Ut.default=Bl;const Ll=u(J)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Ol=({row:e})=>e.original.selectedApplications&&e.original.selectedApplications.length>1?t.jsx(at,{children:t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.original.selectedApplications.map(s=>t.jsx(Ll,{children:s},s))}),children:e.original.appName})}):t.jsx(at,{children:e.original.appName}),_l=({metrics:e,tableSectionId:s})=>{const n=tt(So.breakpoints.down("md")),a=x.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:r,headerGroups:i,rows:c,prepareRow:l,setHiddenColumns:d}=ft.useTable({initialState:a,columns:Ds,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:at}},ft.useGlobalFilter,ft.useSortBy);return vo([{condition:n,columns:["appName","environment"]}],d,Ds),e.length===0?null:t.jsxs(Co,{...o(),rowHeight:"standard",id:s,children:[t.jsx(wo,{headerGroups:i}),t.jsx(To,{...r(),children:c.map(g=>(l(g),t.jsx(Eo,{hover:!0,...g.getRowProps(),children:g.cells.map(f=>t.jsx(Ro,{...f.getCellProps(),children:f.render("Cell")}))})))})]})},Ds=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t.jsx(Ao,{icon:t.jsx(En,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t.jsx($l,{value:e.row.original.timestamp,timeZone:e.row.original.timestamp.includes("23:59")?"UTC":void 0})},{Header:"Application",accessor:"appName",Cell:Ol},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ml=({metrics:e,...s})=>{const n=x.useMemo(()=>e.reduce((o,r)=>o+r.yes,0),[e]),a=x.useMemo(()=>e.reduce((o,r)=>o+r.no,0),[e]);return t.jsx(Sn,{...s,totalYes:n,totalNo:a})},zl=({metrics:e,hoursBack:s})=>{const n=is(),a=is();return e.length===0?t.jsxs(Q,{mt:6,children:[t.jsx(J,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature flag in the selected time period."}),t.jsx(J,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):t.jsxs(x.Suspense,{fallback:null,children:[t.jsx(Q,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t.jsx(Vl,{metrics:e,hoursBack:s,statsSectionId:n})}),t.jsx(Q,{mt:4,children:t.jsx(Ml,{metrics:e,hoursBack:s,statsSectionId:n,tableSectionId:a})}),t.jsx(Q,{mt:4,children:t.jsx(_l,{metrics:e,tableSectionId:a})})]})},Vl=Gs.lazy(()=>Do(()=>import("./FeatureMetricsChart-CJrrWMue.js"),[])),Nl=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),ql=u("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%",alignItems:"center",maxHeight:"200px",overflowY:"auto"})),Wl=u("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.background.alternative,color:e.palette.primary.contrastText},"& > [aria-pressed=true]:hover":{backgroundColor:e.palette.primary.light}})),ks=({title:e,values:s,selectedValues:n,toggleValue:a,toggleValues:o})=>{const r=l=>()=>{a(l)},i=[...s].every(l=>n.includes(l)),c=x.useMemo(()=>Array.from(s).sort((l,d)=>l.localeCompare(d)),[s]);return t.jsxs("div",{children:[t.jsx(Nl,{children:e}),t.jsxs(ql,{children:[o&&s.size>1&&t.jsx(Ie,{size:"small",onClick:o,"aria-pressed":i,children:i?"Unselect":"Select all"}),c.map(l=>t.jsx(Wl,{children:t.jsx(tn,{label:l,onClick:r(l),"aria-pressed":n==null?void 0:n.includes(l),sx:ko})},l))]})]})},Ul=e=>{const s=new Map;return e.forEach(n=>{let a=s.get(n.timestamp);if(a||(a={...n,yes:0,no:0,variants:{}},s.set(n.timestamp,a)),a.yes+=n.yes,a.no+=n.no,n.variants){a.variants=a.variants||{};for(const[o,r]of Object.entries(n.variants))a.variants[o]=(a.variants[o]||0)+r}}),Array.from(s.values()).map(n=>({...n,variants:n.variants&&Object.keys(n.variants).length===0?void 0:n.variants}))},Hl=()=>{const e=k("projectId"),s=k("featureId"),n=Yl(e,s);sn("Metrics");const a=Array.from(n)[0],[o,r]=$o({environment:xt(Fo,a),applications:xt(Io,[]),hoursBack:xt(Po,rt)}),i=Gl(s,o.hoursBack||rt),c=Array.from(i),l=c[0],{environment:d,hoursBack:g}=o,f=o.applications.filter(p=>p!==null);x.useEffect(()=>{o.applications&&o.applications.length===0&&r({applications:c})},[JSON.stringify(c)]);const m=[...i].every(p=>f.includes(p)),{featureMetrics:y}=Tn(s,g),[j,S]=x.useState(y);x.useEffect(()=>{y&&S(y)},[y]);const h=x.useMemo(()=>Ul((j==null?void 0:j.filter(p=>d===p.environment).filter(p=>f.includes(p.appName)))||[]).map(p=>({...p,appName:f.length>1?"all selected":p.appName,selectedApplications:f})),[j,d,JSON.stringify(f)]);return h?t.jsxs(qt,{children:[t.jsxs(Ce,{container:!0,component:"header",spacing:2,children:[t.jsx(Ce,{item:!0,xs:12,md:4,children:t.jsx(C,{condition:n.size>0,show:t.jsx(ks,{title:"Environments",values:n,selectedValues:[d],toggleValue:p=>{r({environment:p})}})})}),t.jsx(Ce,{item:!0,xs:12,md:6,children:t.jsx(C,{condition:i.size>0,show:t.jsx(ks,{title:"Applications",values:i,selectedValues:f,toggleValues:()=>{r(m?{applications:[l]}:{applications:[...i]})},toggleValue:p=>{f.includes(p)?r({applications:f.filter(w=>w!==p)}):r({applications:[...f,p]})}})})}),t.jsx(Ce,{item:!0,xs:12,md:2,children:t.jsx(Dl,{hoursBack:g,setHoursBack:p=>r({hoursBack:p})})})]}),t.jsx(zl,{metrics:h,hoursBack:g})]}):null},Yl=(e,s)=>{const{feature:n}=W(e,s),a=n.environments.map(o=>o.name);return new Set(a)},Gl=(e,s=rt)=>{const{featureMetrics:n=[]}=Tn(e,s),a=n.map(o=>o.appName);return new Set(a)},Jl=({enabled:e,value:s,onChange:n,filter:a,...o})=>{const{projects:r}=on();if(!e)return null;const i=l=>({key:l.id,label:l.name,title:l.description||"",sx:{whiteSpace:"pre-line"}});let c;return a?c=r.filter(l=>a(l.id)).map(i):c=r.map(i),s&&!c.find(l=>l.key===s)&&c.push({key:s,label:s}),t.jsx(Pt,{label:"Project",options:c,value:s,onChange:n,...o})},Kl=(e,s)=>{const n=new Set(e),a=new Set(s);return n.size!==a.size?!1:[...n].every(o=>a.has(o))},$s=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Fs=u(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Ql=u(Vt)({padding:0}),Xl=({projectId:e,open:s,onClose:n,onClick:a,feature:o,changeRequests:r})=>{const i=k("projectId"),{project:c}=Bo(e),{isChangeRequestConfiguredInAnyEnv:l}=ce(e),d=l(),g=x.useMemo(()=>Kl(o.environments.map(y=>y.name),c.environments.map(y=>y.environment)),[o,c]),f=r?r.length>0:!1,m=o.dependencies.length>0||o.children.length>0;return t.jsx(C,{condition:g&&!m&&!f&&!d,show:t.jsx(be,{open:s,onClose:n,onClick:a,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:t.jsxs($s,{children:[t.jsx(Fs,{severity:"success",children:"This feature flag is compatible with the new project."}),t.jsx("p",{children:"Are you sure you want to change the project for this flag?"})]})}),elseShow:t.jsx(be,{open:s,onClick:n,title:"Confirm change project",primaryButtonText:"Close",children:t.jsxs($s,{children:[t.jsx(Fs,{severity:"warning",children:"Cannot proceed with the move"}),t.jsx(C,{condition:m,show:t.jsxs("p",{children:[t.jsx("span",{children:"The feature flag must not have any dependencies."})," ",t.jsx("br",{}),t.jsx("span",{children:"Please remove feature dependencies first."})]})}),t.jsx(C,{condition:!g,show:t.jsx("p",{children:"In order to move a feature flag between two projects, both projects must have the exact same environments enabled."})}),t.jsx(C,{condition:f,show:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"The feature flag must not have any pending change requests. This feature flag is currently referenced in the following change requests:"}),t.jsx(Ql,{children:r==null?void 0:r.map(y=>t.jsx(_e,{children:t.jsxs(ne,{to:`/projects/${i}/change-requests/${y.id}`,children:["View change request"," ",y.id]})},y.id))})]})}),t.jsx(C,{condition:d,show:t.jsxs("p",{children:["You're not allowed to move the feature to project"," ",t.jsx(ne,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Zl=()=>{const{hasAccess:e}=x.useContext(Mt),s=k("projectId"),n=k("featureId"),{feature:a,refetchFeature:o}=W(s,n),[r,i]=x.useState(!1),{changeFeatureProject:c}=lt(),{setToastData:l,setToastApiError:d}=ae(),[g,f]=x.useState(s),{projects:m}=on(),y=Re(),{changeRequests:j}=yn(s,n),S=async()=>{try{g&&(await c(s,n,g),o(),l({title:"Project changed",type:"success"}),i(!1),y(`/projects/${g}/features/${n}/settings`,{replace:!0}))}catch(p){d(G(p))}},h=x.useMemo(()=>m.map(p=>p.id).filter(p=>e(cs,p)),[m,e]);return h.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(Jl,{value:g,onChange:f,label:"Project",filter:p=>h.includes(p),enabled:!0}),t.jsx(Te,{permission:cs,onClick:()=>i(!0),disabled:g===s,projectId:s,children:"Save"}),t.jsx(Xl,{changeRequests:j,projectId:g,open:r,feature:a,onClose:()=>i(!1),onClick:S})]})},ed=u("div")({display:"flex",alignItems:"center"}),td=u(J)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),sd=({projectId:e,featureId:s})=>{var r;const{feature:n}=W(e,s),a=Re(),o=()=>{a(`/projects/${e}/features/${s}/edit`)};return t.jsxs(t.Fragment,{children:[t.jsxs(ed,{children:[t.jsx(td,{children:"Feature information"}),t.jsx(je,{permission:Ve,projectId:e,"data-loading":!0,onClick:o,tooltipProps:{title:"Edit"},children:t.jsx(ze,{})})]}),t.jsxs(J,{children:["Name: ",t.jsx("strong",{children:n.name})]}),t.jsxs(J,{children:["Description:"," ",t.jsx("strong",{children:(r=n.description)!=null&&r.length?n.description:"no description"})]}),t.jsxs(J,{children:["Type: ",t.jsx("strong",{children:n.type})]}),t.jsxs(J,{children:["Impression Data:"," ",t.jsx("strong",{children:n.impressionData?"enabled":"disabled"})]})]})},nt="metadata",At="project",nd=u("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ad=u("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),od=()=>{const e=k("projectId"),s=k("featureId"),[n,a]=x.useState(nt),{uiConfig:o}=We();return t.jsx(qt,{header:"Settings",sx:{padding:0},children:t.jsxs(Q,{sx:{display:"flex"},children:[t.jsx(nd,{children:t.jsxs(Vt,{children:[t.jsx(_e,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>a(nt),selected:n===nt,children:"Metadata"},0),t.jsx(_e,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>a(At),selected:n===At,hidden:!o.flags.P,children:"Project"},1)]})}),t.jsxs(ad,{children:[t.jsx(C,{condition:n===nt,show:t.jsx(sd,{projectId:e,featureId:s})}),t.jsx(C,{condition:n===At&&o.flags.P,show:t.jsx(Zl,{})})]})]})})},rd=({stale:e,showActive:s=!0})=>{if(!e&&!s)return null;const n=e?"Feature flag is deprecated.":"Feature flag is active.",a=e?"Stale":"Active";return t.jsx("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t.jsx(Ne,{color:e?"error":"success",title:n,children:a})})},Is=u("strong")({wordBreak:"break-all"}),id=()=>{const e=k("projectId"),s=k("featureId"),{archivedFeatures:n}=Lo(),a=Oo(e,{name:s});return n?n.some(r=>r.name===s)?t.jsxs("p",{children:["The feature ",t.jsx(Is,{children:s})," has been archived. You can find it on the"," ",t.jsx(ne,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):t.jsxs("p",{children:["The feature ",t.jsx(Is,{children:s})," does not exist. Would you like to"," ",t.jsx(ne,{to:a,children:"create it"}),"?"]}):null},Rn=u(_o)(({theme:e})=>({width:e.spacing(3),height:e.spacing(3)})),cd=u(Rn)(()=>({marginLeft:0})),An=u("div")(({theme:e})=>({display:"flex",flexFlow:"column",gap:e.spacing(.5),alignItems:"flex-start",height:"min-content",whiteSpace:"nowrap"})),ld=u("div")(({theme:e})=>({display:"flex",flexFlow:"row",gap:e.spacing(1)})),dd=({id:e,name:s,imageUrl:n})=>t.jsxs(An,{children:[t.jsx("span",{children:"Last modified by"}),t.jsxs(ld,{children:[t.jsx(cd,{user:{id:e,name:s,imageUrl:n}}),t.jsx(ne,{to:"logs",children:"view change"})]})]}),ud=u(Mo)({flexWrap:"nowrap"}),pd=({collaborators:e})=>t.jsxs(An,{children:[t.jsx("span",{className:"description",children:"Collaborators"}),t.jsx(ud,{users:e,avatarLimit:6,AvatarComponent:Rn})]}),gd=u("article")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"right",[e.breakpoints.down("xl")]:{display:"none"},fontSize:e.typography.body2.fontSize,flex:1})),hd=u("div")(({theme:e})=>({maxWidth:e.spacing(10),minWidth:e.spacing(2),flexGrow:1})),fd=({collaborators:e})=>{if(!e||e.length===0)return null;const s=e[0];return t.jsxs(gd,{children:[t.jsx(dd,{...s}),t.jsx(hd,{}),t.jsx(pd,{collaborators:e})]})},xd=u("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),yd=u("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Ps=u("div")({display:"flex",alignItems:"center"}),Bs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1),marginTop:e.spacing(1),fontSize:e.fontSizes.smallBody,padding:e.spacing(.75,1.5),backgroundColor:e.palette.background.elevation2,borderRadius:`${e.shape.borderRadiusMedium}px`,width:"max-content"})),md=u("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),jd=u("div")({flexShrink:0,display:"flex"}),bd=u("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Sd=u("div")(({theme:e})=>({display:"flex",flexFlow:"row nowrap",gap:e.spacing(4),paddingInline:e.spacing(4),justifyContent:"space-between"})),vd=u(zo)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Cd=u(ne)(()=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),wd=e=>{const s=en("enableLegacyVariants"),n=e.some(a=>{var o;return(o=a.variants)==null?void 0:o.length});return s||n},Td=()=>{var b,T,D;const e=k("projectId"),s=k("featureId"),{favorite:n,unfavorite:a}=Vo(),{refetchFeature:o}=W(e,s),{setToastData:r,setToastApiError:i}=ae(),[c,l]=x.useState(!1),[d,g]=x.useState(!1),[f,m]=x.useState(!1),[y,j]=x.useState(!1),S=tt("(max-width:500px)"),{feature:h,loading:p,error:w,status:I}=W(e,s),B=Re(),{pathname:O}=No(),$=qo(p),P=`/projects/${e}/features/${s}`,R=wd(h.environments),E=[{title:"Overview",path:`${P}`,name:"overview"},{title:"Metrics",path:`${P}/metrics`,name:"Metrics"},...R?[{title:"Variants",path:`${P}/variants`,name:"Variants"}]:[],{title:"Settings",path:`${P}/settings`,name:"Settings"},{title:"Event log",path:`${P}/logs`,name:"Event log"}],_=E.find(v=>v.path===O)??E[0],X=async()=>{try{h!=null&&h.favorite?await a(e,h.name):await n(e,h.name),o()}catch{i("Something went wrong, could not update favorite")}};if(I===404)return t.jsx(id,{});if(w!==void 0)return t.jsx("div",{ref:$});const te=()=>{try{Qo(h.name),j(!0),setTimeout(()=>{j(!1)},3e3)}catch{r({type:"error",title:"Could not copy feature name"})}};return t.jsxs("div",{ref:$,children:[t.jsxs(xd,{children:[t.jsxs(yd,{children:[t.jsxs(Ps,{children:[t.jsx(Wo,{onClick:X,isFavorite:h==null?void 0:h.favorite}),t.jsxs("div",{children:[t.jsxs(Ps,{children:[t.jsxs(md,{"data-loading":!0,children:[h.name," "]}),t.jsx(ue,{title:y?"Copied!":"Copy name",arrow:!0,children:t.jsx(Qe,{onClick:te,style:{marginLeft:8},children:y?t.jsx(Uo,{style:{fontSize:16}}):t.jsx(Ho,{style:{fontSize:16}})})}),t.jsx(C,{condition:!S,show:t.jsx(rd,{stale:h==null?void 0:h.stale})})]}),t.jsx(C,{condition:h.dependencies.length>0,show:t.jsxs(Bs,{children:[t.jsx("b",{children:"Has parent: "}),t.jsx(Cd,{to:`/projects/${h.project}/features/${(b=h==null?void 0:h.dependencies[0])==null?void 0:b.feature}`,children:(T=h==null?void 0:h.dependencies[0])==null?void 0:T.feature})]})}),t.jsx(C,{condition:h.children.length>0,show:t.jsxs(Bs,{children:[t.jsx("b",{children:"Has children:"}),t.jsx(gn,{childFeatures:h.children,project:h.project})]})})]})]}),t.jsxs(jd,{children:[t.jsx(je,{permission:Yo,projectId:e,"data-loading":!0,component:ne,to:`/projects/${e}/features/${s}/copy`,tooltipProps:{title:"Clone"},children:t.jsx(lr,{})}),t.jsx(je,{permission:Go,projectId:e,tooltipProps:{title:"Archive feature flag"},"data-loading":!0,onClick:()=>g(!0),children:t.jsx(dr,{})}),t.jsx(je,{onClick:()=>m(!0),permission:Ve,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t.jsx(ur,{})}),t.jsx(je,{onClick:()=>l(!0),permission:Ve,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t.jsx(Jo,{})})]})]}),t.jsx(bd,{}),t.jsxs(Sd,{children:[t.jsx(Ko,{value:_.path,indicatorColor:"primary",textColor:"primary",children:E.map(v=>t.jsx(vd,{label:v.title,value:v.path,onClick:()=>B(v.path),"data-testid":`TAB-${v.title}`},v.title))}),t.jsx(fd,{collaborators:(D=h.collaborators)==null?void 0:D.users})]})]}),t.jsxs(nn,{children:[t.jsx(Ae,{path:"metrics",element:t.jsx(Hl,{})}),t.jsx(Ae,{path:"logs",element:t.jsx(kr,{})}),t.jsx(Ae,{path:"variants",element:t.jsx(Tl,{})}),t.jsx(Ae,{path:"settings",element:t.jsx(od,{})}),t.jsx(Ae,{path:"*",element:t.jsx(Uc,{})})]}),t.jsx(C,{condition:h.children.length>0,show:t.jsx(dn,{features:h.children,project:e,isOpen:d,onClose:()=>g(!1)}),elseShow:t.jsx(rn,{isOpen:d,onConfirm:()=>{B(`/projects/${e}`)},onClose:()=>g(!1),projectId:e,featureIds:[s]})}),t.jsx(pr,{isStale:h.stale,isOpen:f,onClose:()=>{m(!1),o()},featureId:s,projectId:e}),t.jsx(wn,{open:c,setOpen:l})]})},Dd=Object.freeze(Object.defineProperty({__proto__:null,default:Td},Symbol.toStringTag,{value:"Module"}));export{Dd as F,Zi as d};
|
|
10
|
+
--data-raw '${JSON.stringify(R.patch,void 0,2)}'`,te=p.every(({isValid:A})=>A),b=j((e==null?void 0:e.name)||""),T=b?"Add to existing change request":"Add change to draft",D=m((e==null?void 0:e.name)||""),v=x.useMemo(()=>{var A;return f?"":((A=P[0])==null?void 0:A.stickiness)||g},[f,g,JSON.stringify(P[0]??{})]),F=x.useMemo(()=>["default",...d.filter(A=>A.stickiness).map(A=>A.name)],[d]),L=F.map(A=>({key:A,label:A}));F.includes(v)||L.push({key:v,label:v});const V=async A=>{w(U=>U.map(pe=>({...pe,stickiness:A})))},z=A=>{V(A)},[M,Z]=x.useState();x.useEffect(()=>{Z(void 0),R.error&&Z(R.error)},[R.error]);const ie=()=>{V(g),n(!1)};return f||v===""?t.jsx(uo,{}):t.jsx($t,{open:s,onClose:ie,label:"",children:t.jsxs(Xs,{modal:!0,title:"",description:"Variants allow you to return a variant object if the feature flag is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature flag variants documentation",formatApiCode:X,loading:!s,children:[t.jsxs(Hc,{children:[t.jsxs("div",{children:[t.jsx(Yc,{deprecated:!(e!=null&&e.enabled)}),t.jsx(Gc,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t.jsx(Te,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:$,variant:"outlined",permission:Le,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),t.jsxs(Jc,{onSubmit:_,children:[t.jsx(C,{condition:b,show:S,elseShow:t.jsx(C,{condition:!!D,show:t.jsxs(Kc,{severity:"info",children:[t.jsx("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t.jsx(Xc,{children:p.map(A=>t.jsx(al,{variant:A,variants:p,updateVariant:U=>O(U,A.id),removeVariant:()=>w(U=>as(U.filter(pe=>pe.id!==A.id),1e3)),error:R.error},A.id))}),t.jsx(Te,{onClick:$,variant:"outlined",permission:Le,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"}),t.jsx(el,{}),t.jsx(C,{condition:p.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Zc,{children:t.jsx("p",{children:"Stickiness"})}),t.jsxs(Rs,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Nt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t.jsx("div",{children:t.jsx(tl,{value:v,label:"",editable:!0,onChange:A=>z(A.target.value)})})]}),elseShow:t.jsx(Rs,{children:"This environment has no variants. Get started by adding a variant."})}),t.jsxs(Qc,{severity:"error",hidden:!M,children:[t.jsx("strong",{children:"Error: "}),M]}),t.jsxs(sl,{children:[t.jsx(Ie,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!te,children:D?T:"Save variants"}),t.jsx(nl,{onClick:ie,children:"Cancel"})]})]})]})})},rl=e=>fetch(e).then(qe("ChangeRequest")).then(s=>s.json()),il=(e,s)=>{const{data:n,error:a,mutate:o}=Qs([],Fe(`api/admin/projects/${e}/change-requests/scheduled?variantForFlag=${s}`),rl);return{changeRequests:n,loading:!a&&!n,refetch:o,error:a}},cl=(e,s,n)=>{const{changeRequests:a}=il(e,s),o=a==null?void 0:a.filter(r=>r.environment===n);return o?o.map(r=>r.id):[]},ll=u("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),dl=u("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),ul=u(an,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.neutral.border:e.palette.primary.main})),pl=u("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:s})=>({color:s?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),gl=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),hl=u("div")(({theme:e})=>({margin:e.spacing(3,0)})),fl=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),xl=({environment:e,searchValue:s,children:n})=>{var l;const a=k("projectId"),o=k("featureId"),r=cl(a,o,e.name),i=e.variants??[],c=((l=i[0])==null?void 0:l.stickiness)||"default";return t.jsxs(ll,{children:[t.jsxs(dl,{children:[t.jsxs("div",{children:[t.jsx(ul,{deprecated:!e.enabled}),t.jsx(pl,{deprecated:!e.enabled,children:e.name}),t.jsx(C,{condition:r.length>0,show:t.jsx(go,{sx:{ml:2},children:t.jsx(mn,{scheduledChangeRequestIds:r})})})]}),n]}),t.jsx(C,{condition:i.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(hl,{children:t.jsx(ho,{variants:i,searchValue:s})}),t.jsx(C,{condition:i.length>1,show:t.jsxs(t.Fragment,{children:[t.jsxs(fl,{children:[t.jsx("p",{children:"Stickiness:"}),t.jsx(Ne,{children:c})]}),t.jsxs(gl,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Nt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},yl=u(ke)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ml=({environment:e,permission:s,projectId:n,environmentId:a,onCopyVariantsFrom:o,otherEnvsWithVariants:r})=>{const[i,c]=x.useState(null),l=!!i,d=e.variants??[];return t.jsx(C,{condition:r.length>0&&d.length===0,show:t.jsxs(t.Fragment,{children:[t.jsx(Te,{onClick:g=>{c(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",permission:s,projectId:n,environmentId:a,children:"Copy variants from"}),t.jsx(et,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:r.map(g=>t.jsx(we,{onClick:()=>o(g,e),children:t.jsx(yl,{children:`Copy from ${g.name}`})},g.name))})]})})},jl=({permission:e,projectId:s,environment:n,checked:a,onClick:o,...r})=>{const i=kt(e,s,n);return t.jsxs(we,{disabled:!i,onClick:o,...r,children:[t.jsx(zs,{checked:a}),n]})},bl=u(et)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Sl=u("div")(({theme:e})=>({margin:e.spacing(1,2)})),vl=u(Ie)(({theme:e})=>({marginTop:e.spacing(2)})),Cl=({current:e,environments:s,permission:n,projectId:a,onSubmit:o})=>{var S;const[r,i]=x.useState(null),c=!!r,[l,d]=x.useState([]),g=h=>{d(p=>[...p,h])},f=h=>{d(p=>p.filter(({name:w})=>w!==h.name))},m=h=>{l.includes(h)?f(h):g(h)},y=()=>{d([]),i(null)},j=((S=s.find(h=>h.name===e))==null?void 0:S.variants)??[];return t.jsx(C,{condition:j.length>0&&s.length>1,show:t.jsxs(t.Fragment,{children:[t.jsx(Ie,{onClick:h=>{i(h.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Copy to environment"}),t.jsxs(bl,{anchorEl:r,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[s.filter(h=>h.name!==e).map(h=>t.jsx(jl,{projectId:a,permission:n,environment:h.name,checked:l.includes(h),onClick:()=>m(h)},h.name)),t.jsxs(Sl,{children:[t.jsx(dt,{}),t.jsxs(vl,{variant:"outlined",onClick:()=>{o(l),y()},disabled:l.length===0,children:["Push to selected (",l.length,")"]})]})]})]})})},wl=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Tl=()=>{const{setToastData:e,setToastApiError:s}=ae(),n=ct(),a=tt(n.breakpoints.down("md")),o=k("projectId"),r=k("featureId"),{feature:i,refetchFeature:c,loading:l}=W(o,r),{patchFeatureEnvironmentVariants:d,overrideVariantsInEnvironments:g}=lt(),{refetch:f}=ve(o),{addChange:m}=Ee(),{isChangeRequestConfigured:y}=ce(o),[j,S]=x.useState(""),[h,p]=x.useState(),[w,I]=x.useState(!1),B=x.useMemo(()=>{var b;return((b=i==null?void 0:i.environments)==null?void 0:b.map(T=>({...T,crEnabled:y(T.name)})))||[]},[i.environments]),O=(b,T)=>mo(b,T),$=(b,T)=>{try{const D=yo(T,1e3);return{patch:O(b,D)}}catch(D){return{patch:[],error:G(D)}}},P=b=>({feature:r,action:"patchVariant",payload:{variants:b}}),R=async(b,T)=>{if(b.crEnabled)await m(o,b.name,P(T)),f();else{const D=b.variants??[],{patch:v,error:F}=$(D,T);if(v.length===0)return;if(F){e({type:"error",title:F});return}await d(o,r,b.name,v)}c()},E=async(b,T)=>{try{const D=T.filter(({crEnabled:z})=>z),v=T.filter(({crEnabled:z})=>!z);D.length&&await Promise.all(D.map(z=>m(o,z.name,P(b)))),v.length&&await g(o,r,b,v.map(({name:z})=>z)),f(),c();const F=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",L=D.length?`Variants push added to ${D.length===1?`${D[0].name} draft`:`${D.length} drafts`}`:"",V=`${F}${F&&L?". ":""}${L}`;e({title:V,type:"success"})}catch(D){s(G(D))}},_=b=>{p(b),I(!0)},X=async b=>{if(h)try{await R(h,b),I(!1),e({title:h.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(T){s(G(T))}},te=async(b,T)=>{try{const D=b.variants??[];await R(T,D),e({title:T.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(D){s(G(D))}};return t.jsxs(qt,{isLoading:l,header:t.jsx(fo,{title:"Variants",actions:t.jsx(C,{condition:!a,show:t.jsx(t.Fragment,{children:t.jsx(os,{initialValue:j,onChange:S})})}),children:t.jsx(C,{condition:a,show:t.jsx(os,{initialValue:j,onChange:S})})}),children:[t.jsx(xo,{}),B.map(b=>{var D;const T=B.filter(({name:v,variants:F})=>v!==b.name&&(F==null?void 0:F.length));return t.jsx(xl,{environment:b,searchValue:j,children:t.jsxs(wl,{children:[t.jsx(Cl,{current:b.name,environments:B,permission:Le,projectId:o,onSubmit:v=>E(b.variants??[],v)}),t.jsx(ml,{environment:b,permission:Le,projectId:o,environmentId:b.name,onCopyVariantsFrom:te,otherEnvsWithVariants:T}),t.jsx(C,{condition:!!((D=b.variants)!=null&&D.length),show:t.jsx(je,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>_(b),permission:Le,projectId:o,environmentId:b.name,tooltipProps:{title:"Edit variants"},children:t.jsx(ze,{})}),elseShow:t.jsx(Te,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>_(b),variant:"outlined",permission:Le,projectId:o,environmentId:b.name,children:"Add variant"})})]})},b.name)}),t.jsx(ol,{environment:h,open:w,setOpen:I,getApiPayload:$,getCrPayload:P,onConfirm:X})]})},El=Fe("api/admin/client-metrics/features"),Tn=(e,s)=>{const n=Fe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${s}`),{data:a,error:o}=Ys(n,()=>Rl(n)),r=x.useCallback(()=>{Ot(El).catch(console.warn)},[]);return{featureMetrics:a==null?void 0:a.data,loading:!o&&!a,refetchFeatureMetrics:r,error:o}},Rl=e=>fetch(e).then(qe("Features")).then(s=>s.json()).then(),Al=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),rt=48,Dl=({hoursBack:e,setHoursBack:s})=>{const{trackEvent:n}=Se(),a=c=>{s(Number.parseInt(c)),n("feature-metrics",{props:{eventType:"change-period",hoursBack:c}})},{isEnterprise:o}=We(),r=o()?[...As,...kl]:As,i=r.map(c=>Number(c.key)).includes(e)?e:rt;return x.useEffect(()=>{e!==i&&s(i)},[e]),t.jsxs("div",{children:[t.jsx(Al,{children:"Period"}),t.jsx(Pt,{name:"feature-metrics-period",id:"feature-metrics-period",options:r,value:String(i),onChange:a,fullWidth:!0})]})},As=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:"48",label:"Last 48 hours"}],kl=[{key:`${7*24}`,label:"Last 7 days"},{key:`${30*24}`,label:"Last 30 days"},{key:`${90*24}`,label:"Last 90 days"}],$l=({value:e,timeZone:s})=>{const{locationSettings:n}=Us(),a=e?e instanceof Date?rs(e,n.locale,s):rs(Hs(e),n.locale,s):void 0;return t.jsx(at,{lineClamp:1,children:a})};var Ut={},Fl=bo;Object.defineProperty(Ut,"__esModule",{value:!0});var En=Ut.default=void 0,Il=Fl(jo()),Pl=t,Bl=(0,Il.default)((0,Pl.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment");En=Ut.default=Bl;const Ll=u(J)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Ol=({row:e})=>e.original.selectedApplications&&e.original.selectedApplications.length>1?t.jsx(at,{children:t.jsx(Xe,{tooltip:t.jsx(t.Fragment,{children:e.original.selectedApplications.map(s=>t.jsx(Ll,{children:s},s))}),children:e.original.appName})}):t.jsx(at,{children:e.original.appName}),_l=({metrics:e,tableSectionId:s})=>{const n=tt(So.breakpoints.down("md")),a=x.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:r,headerGroups:i,rows:c,prepareRow:l,setHiddenColumns:d}=ft.useTable({initialState:a,columns:Ds,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:at}},ft.useGlobalFilter,ft.useSortBy);return vo([{condition:n,columns:["appName","environment"]}],d,Ds),e.length===0?null:t.jsxs(Co,{...o(),rowHeight:"standard",id:s,children:[t.jsx(wo,{headerGroups:i}),t.jsx(To,{...r(),children:c.map(g=>(l(g),t.jsx(Eo,{hover:!0,...g.getRowProps(),children:g.cells.map(f=>t.jsx(Ro,{...f.getCellProps(),children:f.render("Cell")}))})))})]})},Ds=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t.jsx(Ao,{icon:t.jsx(En,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t.jsx($l,{value:e.row.original.timestamp,timeZone:e.row.original.timestamp.includes("23:59")?"UTC":void 0})},{Header:"Application",accessor:"appName",Cell:Ol},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ml=({metrics:e,...s})=>{const n=x.useMemo(()=>e.reduce((o,r)=>o+r.yes,0),[e]),a=x.useMemo(()=>e.reduce((o,r)=>o+r.no,0),[e]);return t.jsx(Sn,{...s,totalYes:n,totalNo:a})},zl=({metrics:e,hoursBack:s})=>{const n=is(),a=is();return e.length===0?t.jsxs(Q,{mt:6,children:[t.jsx(J,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature flag in the selected time period."}),t.jsx(J,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):t.jsxs(x.Suspense,{fallback:null,children:[t.jsx(Q,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t.jsx(Vl,{metrics:e,hoursBack:s,statsSectionId:n})}),t.jsx(Q,{mt:4,children:t.jsx(Ml,{metrics:e,hoursBack:s,statsSectionId:n,tableSectionId:a})}),t.jsx(Q,{mt:4,children:t.jsx(_l,{metrics:e,tableSectionId:a})})]})},Vl=Gs.lazy(()=>Do(()=>import("./FeatureMetricsChart-DEo4WxO1.js"),[])),Nl=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),ql=u("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%",alignItems:"center",maxHeight:"200px",overflowY:"auto"})),Wl=u("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.background.alternative,color:e.palette.primary.contrastText},"& > [aria-pressed=true]:hover":{backgroundColor:e.palette.primary.light}})),ks=({title:e,values:s,selectedValues:n,toggleValue:a,toggleValues:o})=>{const r=l=>()=>{a(l)},i=[...s].every(l=>n.includes(l)),c=x.useMemo(()=>Array.from(s).sort((l,d)=>l.localeCompare(d)),[s]);return t.jsxs("div",{children:[t.jsx(Nl,{children:e}),t.jsxs(ql,{children:[o&&s.size>1&&t.jsx(Ie,{size:"small",onClick:o,"aria-pressed":i,children:i?"Unselect":"Select all"}),c.map(l=>t.jsx(Wl,{children:t.jsx(tn,{label:l,onClick:r(l),"aria-pressed":n==null?void 0:n.includes(l),sx:ko})},l))]})]})},Ul=e=>{const s=new Map;return e.forEach(n=>{let a=s.get(n.timestamp);if(a||(a={...n,yes:0,no:0,variants:{}},s.set(n.timestamp,a)),a.yes+=n.yes,a.no+=n.no,n.variants){a.variants=a.variants||{};for(const[o,r]of Object.entries(n.variants))a.variants[o]=(a.variants[o]||0)+r}}),Array.from(s.values()).map(n=>({...n,variants:n.variants&&Object.keys(n.variants).length===0?void 0:n.variants}))},Hl=()=>{const e=k("projectId"),s=k("featureId"),n=Yl(e,s);sn("Metrics");const a=Array.from(n)[0],[o,r]=$o({environment:xt(Fo,a),applications:xt(Io,[]),hoursBack:xt(Po,rt)}),i=Gl(s,o.hoursBack||rt),c=Array.from(i),l=c[0],{environment:d,hoursBack:g}=o,f=o.applications.filter(p=>p!==null);x.useEffect(()=>{o.applications&&o.applications.length===0&&r({applications:c})},[JSON.stringify(c)]);const m=[...i].every(p=>f.includes(p)),{featureMetrics:y}=Tn(s,g),[j,S]=x.useState(y);x.useEffect(()=>{y&&S(y)},[y]);const h=x.useMemo(()=>Ul((j==null?void 0:j.filter(p=>d===p.environment).filter(p=>f.includes(p.appName)))||[]).map(p=>({...p,appName:f.length>1?"all selected":p.appName,selectedApplications:f})),[j,d,JSON.stringify(f)]);return h?t.jsxs(qt,{children:[t.jsxs(Ce,{container:!0,component:"header",spacing:2,children:[t.jsx(Ce,{item:!0,xs:12,md:4,children:t.jsx(C,{condition:n.size>0,show:t.jsx(ks,{title:"Environments",values:n,selectedValues:[d],toggleValue:p=>{r({environment:p})}})})}),t.jsx(Ce,{item:!0,xs:12,md:6,children:t.jsx(C,{condition:i.size>0,show:t.jsx(ks,{title:"Applications",values:i,selectedValues:f,toggleValues:()=>{r(m?{applications:[l]}:{applications:[...i]})},toggleValue:p=>{f.includes(p)?r({applications:f.filter(w=>w!==p)}):r({applications:[...f,p]})}})})}),t.jsx(Ce,{item:!0,xs:12,md:2,children:t.jsx(Dl,{hoursBack:g,setHoursBack:p=>r({hoursBack:p})})})]}),t.jsx(zl,{metrics:h,hoursBack:g})]}):null},Yl=(e,s)=>{const{feature:n}=W(e,s),a=n.environments.map(o=>o.name);return new Set(a)},Gl=(e,s=rt)=>{const{featureMetrics:n=[]}=Tn(e,s),a=n.map(o=>o.appName);return new Set(a)},Jl=({enabled:e,value:s,onChange:n,filter:a,...o})=>{const{projects:r}=on();if(!e)return null;const i=l=>({key:l.id,label:l.name,title:l.description||"",sx:{whiteSpace:"pre-line"}});let c;return a?c=r.filter(l=>a(l.id)).map(i):c=r.map(i),s&&!c.find(l=>l.key===s)&&c.push({key:s,label:s}),t.jsx(Pt,{label:"Project",options:c,value:s,onChange:n,...o})},Kl=(e,s)=>{const n=new Set(e),a=new Set(s);return n.size!==a.size?!1:[...n].every(o=>a.has(o))},$s=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Fs=u(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Ql=u(Vt)({padding:0}),Xl=({projectId:e,open:s,onClose:n,onClick:a,feature:o,changeRequests:r})=>{const i=k("projectId"),{project:c}=Bo(e),{isChangeRequestConfiguredInAnyEnv:l}=ce(e),d=l(),g=x.useMemo(()=>Kl(o.environments.map(y=>y.name),c.environments.map(y=>y.environment)),[o,c]),f=r?r.length>0:!1,m=o.dependencies.length>0||o.children.length>0;return t.jsx(C,{condition:g&&!m&&!f&&!d,show:t.jsx(be,{open:s,onClose:n,onClick:a,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:t.jsxs($s,{children:[t.jsx(Fs,{severity:"success",children:"This feature flag is compatible with the new project."}),t.jsx("p",{children:"Are you sure you want to change the project for this flag?"})]})}),elseShow:t.jsx(be,{open:s,onClick:n,title:"Confirm change project",primaryButtonText:"Close",children:t.jsxs($s,{children:[t.jsx(Fs,{severity:"warning",children:"Cannot proceed with the move"}),t.jsx(C,{condition:m,show:t.jsxs("p",{children:[t.jsx("span",{children:"The feature flag must not have any dependencies."})," ",t.jsx("br",{}),t.jsx("span",{children:"Please remove feature dependencies first."})]})}),t.jsx(C,{condition:!g,show:t.jsx("p",{children:"In order to move a feature flag between two projects, both projects must have the exact same environments enabled."})}),t.jsx(C,{condition:f,show:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"The feature flag must not have any pending change requests. This feature flag is currently referenced in the following change requests:"}),t.jsx(Ql,{children:r==null?void 0:r.map(y=>t.jsx(_e,{children:t.jsxs(ne,{to:`/projects/${i}/change-requests/${y.id}`,children:["View change request"," ",y.id]})},y.id))})]})}),t.jsx(C,{condition:d,show:t.jsxs("p",{children:["You're not allowed to move the feature to project"," ",t.jsx(ne,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Zl=()=>{const{hasAccess:e}=x.useContext(Mt),s=k("projectId"),n=k("featureId"),{feature:a,refetchFeature:o}=W(s,n),[r,i]=x.useState(!1),{changeFeatureProject:c}=lt(),{setToastData:l,setToastApiError:d}=ae(),[g,f]=x.useState(s),{projects:m}=on(),y=Re(),{changeRequests:j}=yn(s,n),S=async()=>{try{g&&(await c(s,n,g),o(),l({title:"Project changed",type:"success"}),i(!1),y(`/projects/${g}/features/${n}/settings`,{replace:!0}))}catch(p){d(G(p))}},h=x.useMemo(()=>m.map(p=>p.id).filter(p=>e(cs,p)),[m,e]);return h.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(Jl,{value:g,onChange:f,label:"Project",filter:p=>h.includes(p),enabled:!0}),t.jsx(Te,{permission:cs,onClick:()=>i(!0),disabled:g===s,projectId:s,children:"Save"}),t.jsx(Xl,{changeRequests:j,projectId:g,open:r,feature:a,onClose:()=>i(!1),onClick:S})]})},ed=u("div")({display:"flex",alignItems:"center"}),td=u(J)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),sd=({projectId:e,featureId:s})=>{var r;const{feature:n}=W(e,s),a=Re(),o=()=>{a(`/projects/${e}/features/${s}/edit`)};return t.jsxs(t.Fragment,{children:[t.jsxs(ed,{children:[t.jsx(td,{children:"Feature information"}),t.jsx(je,{permission:Ve,projectId:e,"data-loading":!0,onClick:o,tooltipProps:{title:"Edit"},children:t.jsx(ze,{})})]}),t.jsxs(J,{children:["Name: ",t.jsx("strong",{children:n.name})]}),t.jsxs(J,{children:["Description:"," ",t.jsx("strong",{children:(r=n.description)!=null&&r.length?n.description:"no description"})]}),t.jsxs(J,{children:["Type: ",t.jsx("strong",{children:n.type})]}),t.jsxs(J,{children:["Impression Data:"," ",t.jsx("strong",{children:n.impressionData?"enabled":"disabled"})]})]})},nt="metadata",At="project",nd=u("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ad=u("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),od=()=>{const e=k("projectId"),s=k("featureId"),[n,a]=x.useState(nt),{uiConfig:o}=We();return t.jsx(qt,{header:"Settings",sx:{padding:0},children:t.jsxs(Q,{sx:{display:"flex"},children:[t.jsx(nd,{children:t.jsxs(Vt,{children:[t.jsx(_e,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>a(nt),selected:n===nt,children:"Metadata"},0),t.jsx(_e,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>a(At),selected:n===At,hidden:!o.flags.P,children:"Project"},1)]})}),t.jsxs(ad,{children:[t.jsx(C,{condition:n===nt,show:t.jsx(sd,{projectId:e,featureId:s})}),t.jsx(C,{condition:n===At&&o.flags.P,show:t.jsx(Zl,{})})]})]})})},rd=({stale:e,showActive:s=!0})=>{if(!e&&!s)return null;const n=e?"Feature flag is deprecated.":"Feature flag is active.",a=e?"Stale":"Active";return t.jsx("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t.jsx(Ne,{color:e?"error":"success",title:n,children:a})})},Is=u("strong")({wordBreak:"break-all"}),id=()=>{const e=k("projectId"),s=k("featureId"),{archivedFeatures:n}=Lo(),a=Oo(e,{name:s});return n?n.some(r=>r.name===s)?t.jsxs("p",{children:["The feature ",t.jsx(Is,{children:s})," has been archived. You can find it on the"," ",t.jsx(ne,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):t.jsxs("p",{children:["The feature ",t.jsx(Is,{children:s})," does not exist. Would you like to"," ",t.jsx(ne,{to:a,children:"create it"}),"?"]}):null},Rn=u(_o)(({theme:e})=>({width:e.spacing(3),height:e.spacing(3)})),cd=u(Rn)(()=>({marginLeft:0})),An=u("div")(({theme:e})=>({display:"flex",flexFlow:"column",gap:e.spacing(.5),alignItems:"flex-start",height:"min-content",whiteSpace:"nowrap"})),ld=u("div")(({theme:e})=>({display:"flex",flexFlow:"row",gap:e.spacing(1)})),dd=({id:e,name:s,imageUrl:n})=>t.jsxs(An,{children:[t.jsx("span",{children:"Last modified by"}),t.jsxs(ld,{children:[t.jsx(cd,{user:{id:e,name:s,imageUrl:n}}),t.jsx(ne,{to:"logs",children:"view change"})]})]}),ud=u(Mo)({flexWrap:"nowrap"}),pd=({collaborators:e})=>t.jsxs(An,{children:[t.jsx("span",{className:"description",children:"Collaborators"}),t.jsx(ud,{users:e,avatarLimit:6,AvatarComponent:Rn})]}),gd=u("article")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"right",[e.breakpoints.down("xl")]:{display:"none"},fontSize:e.typography.body2.fontSize,flex:1})),hd=u("div")(({theme:e})=>({maxWidth:e.spacing(10),minWidth:e.spacing(2),flexGrow:1})),fd=({collaborators:e})=>{if(!e||e.length===0)return null;const s=e[0];return t.jsxs(gd,{children:[t.jsx(dd,{...s}),t.jsx(hd,{}),t.jsx(pd,{collaborators:e})]})},xd=u("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),yd=u("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Ps=u("div")({display:"flex",alignItems:"center"}),Bs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1),marginTop:e.spacing(1),fontSize:e.fontSizes.smallBody,padding:e.spacing(.75,1.5),backgroundColor:e.palette.background.elevation2,borderRadius:`${e.shape.borderRadiusMedium}px`,width:"max-content"})),md=u("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),jd=u("div")({flexShrink:0,display:"flex"}),bd=u("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Sd=u("div")(({theme:e})=>({display:"flex",flexFlow:"row nowrap",gap:e.spacing(4),paddingInline:e.spacing(4),justifyContent:"space-between"})),vd=u(zo)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Cd=u(ne)(()=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),wd=e=>{const s=en("enableLegacyVariants"),n=e.some(a=>{var o;return(o=a.variants)==null?void 0:o.length});return s||n},Td=()=>{var b,T,D;const e=k("projectId"),s=k("featureId"),{favorite:n,unfavorite:a}=Vo(),{refetchFeature:o}=W(e,s),{setToastData:r,setToastApiError:i}=ae(),[c,l]=x.useState(!1),[d,g]=x.useState(!1),[f,m]=x.useState(!1),[y,j]=x.useState(!1),S=tt("(max-width:500px)"),{feature:h,loading:p,error:w,status:I}=W(e,s),B=Re(),{pathname:O}=No(),$=qo(p),P=`/projects/${e}/features/${s}`,R=wd(h.environments),E=[{title:"Overview",path:`${P}`,name:"overview"},{title:"Metrics",path:`${P}/metrics`,name:"Metrics"},...R?[{title:"Variants",path:`${P}/variants`,name:"Variants"}]:[],{title:"Settings",path:`${P}/settings`,name:"Settings"},{title:"Event log",path:`${P}/logs`,name:"Event log"}],_=E.find(v=>v.path===O)??E[0],X=async()=>{try{h!=null&&h.favorite?await a(e,h.name):await n(e,h.name),o()}catch{i("Something went wrong, could not update favorite")}};if(I===404)return t.jsx(id,{});if(w!==void 0)return t.jsx("div",{ref:$});const te=()=>{try{Qo(h.name),j(!0),setTimeout(()=>{j(!1)},3e3)}catch{r({type:"error",title:"Could not copy feature name"})}};return t.jsxs("div",{ref:$,children:[t.jsxs(xd,{children:[t.jsxs(yd,{children:[t.jsxs(Ps,{children:[t.jsx(Wo,{onClick:X,isFavorite:h==null?void 0:h.favorite}),t.jsxs("div",{children:[t.jsxs(Ps,{children:[t.jsxs(md,{"data-loading":!0,children:[h.name," "]}),t.jsx(ue,{title:y?"Copied!":"Copy name",arrow:!0,children:t.jsx(Qe,{onClick:te,style:{marginLeft:8},children:y?t.jsx(Uo,{style:{fontSize:16}}):t.jsx(Ho,{style:{fontSize:16}})})}),t.jsx(C,{condition:!S,show:t.jsx(rd,{stale:h==null?void 0:h.stale})})]}),t.jsx(C,{condition:h.dependencies.length>0,show:t.jsxs(Bs,{children:[t.jsx("b",{children:"Has parent: "}),t.jsx(Cd,{to:`/projects/${h.project}/features/${(b=h==null?void 0:h.dependencies[0])==null?void 0:b.feature}`,children:(T=h==null?void 0:h.dependencies[0])==null?void 0:T.feature})]})}),t.jsx(C,{condition:h.children.length>0,show:t.jsxs(Bs,{children:[t.jsx("b",{children:"Has children:"}),t.jsx(gn,{childFeatures:h.children,project:h.project})]})})]})]}),t.jsxs(jd,{children:[t.jsx(je,{permission:Yo,projectId:e,"data-loading":!0,component:ne,to:`/projects/${e}/features/${s}/copy`,tooltipProps:{title:"Clone"},children:t.jsx(lr,{})}),t.jsx(je,{permission:Go,projectId:e,tooltipProps:{title:"Archive feature flag"},"data-loading":!0,onClick:()=>g(!0),children:t.jsx(dr,{})}),t.jsx(je,{onClick:()=>m(!0),permission:Ve,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t.jsx(ur,{})}),t.jsx(je,{onClick:()=>l(!0),permission:Ve,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t.jsx(Jo,{})})]})]}),t.jsx(bd,{}),t.jsxs(Sd,{children:[t.jsx(Ko,{value:_.path,indicatorColor:"primary",textColor:"primary",children:E.map(v=>t.jsx(vd,{label:v.title,value:v.path,onClick:()=>B(v.path),"data-testid":`TAB-${v.title}`},v.title))}),t.jsx(fd,{collaborators:(D=h.collaborators)==null?void 0:D.users})]})]}),t.jsxs(nn,{children:[t.jsx(Ae,{path:"metrics",element:t.jsx(Hl,{})}),t.jsx(Ae,{path:"logs",element:t.jsx(kr,{})}),t.jsx(Ae,{path:"variants",element:t.jsx(Tl,{})}),t.jsx(Ae,{path:"settings",element:t.jsx(od,{})}),t.jsx(Ae,{path:"*",element:t.jsx(Uc,{})})]}),t.jsx(C,{condition:h.children.length>0,show:t.jsx(dn,{features:h.children,project:e,isOpen:d,onClose:()=>g(!1)}),elseShow:t.jsx(rn,{isOpen:d,onConfirm:()=>{B(`/projects/${e}`)},onClose:()=>g(!1),projectId:e,featureIds:[s]})}),t.jsx(pr,{isStale:h.stale,isOpen:f,onClose:()=>{m(!1),o()},featureId:s,projectId:e}),t.jsx(wn,{open:c,setOpen:l})]})},Dd=Object.freeze(Object.defineProperty({__proto__:null,default:Td},Symbol.toStringTag,{value:"Module"}));export{Dd as F,Zi as d};
|