unleash-server 4.22.0-beta.2 → 4.22.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{CreateProject-b852657c.js → CreateProject-f956b9a9.js} +1 -1
- package/frontend/build/static/{Error-29ef2974.js → Error-50738ec1.js} +1 -1
- package/frontend/build/static/{ExpandMore-4b3cbf87.js → ExpandMore-fa91a7f3.js} +1 -1
- package/frontend/build/static/{FeatureArchiveDialog-f9d8c71d.js → FeatureArchiveDialog-72b90a0e.js} +1 -1
- package/frontend/build/static/{FeatureMetricsChart-86cc2280.js → FeatureMetricsChart-1e05efb3.js} +1 -1
- package/frontend/build/static/{FeatureViewLazyExport-1366d6bf.js → FeatureViewLazyExport-fe102147.js} +2 -2
- package/frontend/build/static/{LazyAdminExport-d9800386.js → LazyAdminExport-eef83754.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-ef4471a8.js → LazyProjectExport-0b9505b9.js} +2 -2
- package/frontend/build/static/{NetworkOverview-4b90dc34.js → NetworkOverview-74c0873e.js} +1 -1
- package/frontend/build/static/{NetworkTraffic-c9de9d5f.js → NetworkTraffic-6d92b15a.js} +1 -1
- package/frontend/build/static/{Playground-ee072216.js → Playground-066018d8.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-b65caaa6.js → StrategyItemContainer-dd157f67.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-5c47f5e0.js → chartjs-adapter-date-fns.esm-f7b23ba0.js} +1 -1
- package/frontend/build/static/{index-031b8ec3.js → index-bde9bd95.js} +1 -1
- package/frontend/build/static/{index-bbbae9a8.js → index-cae4a71b.js} +1 -1
- package/frontend/build/static/{index-193ec8c2.js → index-e6748c1b.js} +2 -2
- package/frontend/build/static/{unknownify-88f06eea.js → unknownify-7440eed8.js} +1 -1
- package/frontend/build/static/{useProjectRole-d8edb83e.js → useProjectRole-379404dd.js} +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
href="https://fonts.googleapis.com/css2?family=Sen:wght@400;700;800&display=swap"
|
|
17
17
|
rel="stylesheet"
|
|
18
18
|
/>
|
|
19
|
-
<script type="module" crossorigin src="/static/index-
|
|
19
|
+
<script type="module" crossorigin src="/static/index-e6748c1b.js"></script>
|
|
20
20
|
<link rel="stylesheet" href="/static/index-1fa04e71.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a2 as E,aq as N,H as w,ar as I,as as U,at as S,j as e,au as x,av as D,aw as O,ax as _,a4 as b,ay as k}from"./index-
|
|
1
|
+
import{a2 as E,aq as N,H as w,ar as I,as as U,at as S,j as e,au as x,av as D,aw as O,ax as _,a4 as b,ay as k}from"./index-e6748c1b.js";const q=()=>{const{setToastData:c,setToastApiError:n}=E(),{refetchUser:i}=N(),{uiConfig:d}=w(),t=I(),{projectId:a,projectName:l,projectDesc:u,setProjectId:p,setProjectName:j,setProjectDesc:m,getProjectPayload:o,clearErrors:r,validateProjectId:s,validateName:h,errors:P}=U(),{createProject:g,loading:f}=S();return e(x,{loading:f,title:"Create project",description:"Projects allows you to group feature toggles together in the management UI.",documentationLink:"https://docs.getunleash.io/reference/projects",documentationLinkLabel:"Projects documentation",formatApiCode:()=>`curl --location --request POST '${d.unleashUrl}/api/admin/projects' \\
|
|
2
2
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
3
|
--header 'Content-Type: application/json' \\
|
|
4
4
|
--data-raw '${JSON.stringify(o(),void 0,2)}'`,children:e(D,{errors:P,handleSubmit:async C=>{C.preventDefault(),r();const y=h(),v=await s();if(y&&v){const A=o();try{await g(A),i(),t(`/projects/${a}`),c({title:"Project created",text:"Now you can add toggles to this project",confetti:!0,type:"success"})}catch(T){n(b(T))}}},handleCancel:()=>{t(k)},projectId:a,setProjectId:p,projectName:l,setProjectName:j,projectDesc:u,setProjectDesc:m,mode:"Create",clearErrors:r,validateProjectId:s,children:e(O,{name:"project",permission:_})})})};export{q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as r,j as o}from"./index-
|
|
1
|
+
import{c as r,j as o}from"./index-e6748c1b.js";const a=r(o("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}),"Error");export{a as E};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a,j as o}from"./index-
|
|
1
|
+
import{c as a,j as o}from"./index-e6748c1b.js";const e=a(o("path",{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"}),"ExpandMore");export{e as E};
|
package/frontend/build/static/{FeatureArchiveDialog-f9d8c71d.js → FeatureArchiveDialog-72b90a0e.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aG as A,a$ as E,f as p,aY as C,j as o,C as w,A as M,T as b,c0 as J,cr as x,r as d,cs as Q,ct as X,aZ as Z,a_ as I,a2 as S,H as ee,ar as P,aH as D,aT as te,cu as ae,au as ne,ap as se,cv as re,cw as oe,cx as ie,cy as ce,b6 as $,cz as ue,b0 as le,a4 as v,cA as ge,s as j,aX as de,cB as he,cC as ye,F as fe,bz as N}from"./index-
|
|
1
|
+
import{aG as A,a$ as E,f as p,aY as C,j as o,C as w,A as M,T as b,c0 as J,cr as x,r as d,cs as Q,ct as X,aZ as Z,a_ as I,a2 as S,H as ee,ar as P,aH as D,aT as te,cu as ae,au as ne,ap as se,cv as re,cw as oe,cx as ie,cy as ce,b6 as $,cz as ue,b0 as le,a4 as v,cA as ge,s as j,aX as de,cB as he,cC as ye,F as fe,bz as N}from"./index-e6748c1b.js";const Re=({isOpen:e,onConfirm:t,onClose:a,showBanner:n,environment:s,messageComponent:r})=>{const i=A("projectId"),{data:l}=E(i),{changeRequestInReviewOrApproved:u,alert:g}=J(l),c=u(s||"");return p(C,{open:e,primaryButtonText:c?"Add to existing change request":"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:t,onClose:a,title:"Request changes",fullWidth:!0,children:[o(w,{condition:c,show:g}),o(w,{condition:Boolean(n),show:p(M,{severity:"info",sx:{mb:2},children:["Change requests feature is enabled for ",s,". 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."]})}),o(b,{variant:"body2",color:"text.secondary",children:"Your suggestion:"}),r]})},pe=(e,t)=>{const a={};return t.parameters.forEach(n=>{a[n.name]=me(e,n)}),{name:t.name,constraints:[],parameters:a}},me=(e,t)=>t.name==="rollout"||t.name==="percentage"||t.type==="percentage"?"50":t.name==="stickiness"?"default":t.name==="groupId"?e:t.type==="boolean"?"false":"",Ae=()=>{const e=A("projectId"),t=A("featureId"),a=x("environmentId"),n=x("strategyName"),[s,r]=d.useState({}),[i,l]=d.useState([]),{strategyDefinition:u}=Q(n),g=X(),{addStrategyToFeature:c,loading:h}=Z(),{addChange:m}=I(),{setToastData:T,setToastApiError:O}=S(),{uiConfig:Y}=ee(),{unleashUrl:z}=Y,_=P(),{feature:y,refetchFeature:F}=D(e,t),q=d.useRef(y),{isChangeRequestConfigured:k}=te(e),{refetch:L}=E(e),{data:R,staleDataNotification:U,forceRefreshCache:W}=ae({unleashGetter:D,params:[e,t],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},y,{afterSubmitAction:F},ge);d.useEffect(()=>{q.current.name===""&&y.name&&(W(y),q.current=y)},[y]),d.useEffect(()=>{u&&r(pe(t,u))},[t,u]);const G=async f=>{await c(e,t,a,f),T({title:"Strategy created",type:"success",confetti:!0})},H=async f=>{await m(e,a,{action:"addStrategy",feature:t,payload:f}),T({title:"Strategy added to draft",type:"success",confetti:!0}),L()},V=async()=>{const f=ue(s,i);try{k(a)?await H(f):await G(f),F(),_(le(e,t))}catch(K){O(v(K))}};return!R||!R.project?null:p(ne,{modal:!0,title:se(n),description:re,documentationLink:oe,documentationLinkLabel:ie,formatApiCode:()=>be(e,t,a,s,z),children:[o(ce,{projectId:e,feature:R,strategy:s,setStrategy:r,segments:i,setSegments:l,environmentId:a,onSubmit:V,loading:h,permission:$,errors:g,isChangeRequest:k(a)}),U]})},Te=(e,t,a,n)=>{const s=new URLSearchParams({environmentId:a,strategyName:n});return`/projects/${e}/features/${t}/strategies/create?${s}`},be=(e,t,a,n,s)=>{if(!s)return"";const r=`${s}/api/admin/projects/${e}/features/${t}/environments/${a}/strategies`,i=JSON.stringify(n,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}'`},B=j("p")(({theme:e})=>({marginBottom:e.spacing(.5),fontSize:e.fontSizes.bodySize})),we=({open:e,environmentName:t,featureId:a,projectId:n,onClose:s})=>{const r=P(),i=Te(n,a,t,"default");return p(C,{open:e,maxWidth:"sm",onClose:()=>s(),title:"You need to add a strategy to your toggle",primaryButtonText:"Take me directly to add strategy",permissionButton:o(de,{type:"button",permission:$,projectId:n,environmentId:t,onClick:()=>{s(),r(i)},children:"Take me directly to add strategy"}),secondaryButtonText:"Cancel",children:[o(B,{children:"Before you can enable the toggle in the environment, you need to add an activation strategy."}),o(B,{children:"You can add the activation strategy by selecting the toggle, open the environment accordion and add the activation strategy."})]})},Ee="You can not enable the environment before it has strategies",Fe=e=>{const{setToastData:t,setToastApiError:a}=S(),{addChange:n}=I(),{refetch:s}=E(e),[r,i]=d.useState({isOpen:!1}),l=d.useCallback((c,h,m)=>{i({featureName:c,environment:h,enabled:m,isOpen:!0})},[]),u=d.useCallback(()=>{i(c=>({...c,isOpen:!1}))},[]),g=d.useCallback(async()=>{try{await n(e,r.environment,{feature:r.featureName,action:"updateEnabled",payload:{enabled:Boolean(r.enabled)}}),s(),i(c=>({...c,isOpen:!1})),t({type:"success",title:"Changes added to the draft!"})}catch(c){a(v(c)),i(h=>({...h,isOpen:!1}))}},[n]);return{onChangeRequestToggle:l,onChangeRequestToggleClose:u,onChangeRequestToggleConfirm:g,changeRequestDialogDetails:r}},qe=({enabled:e,featureName:t,environment:a})=>p(b,{"data-testid":"update-enabled-message",children:[o("strong",{children:e?"Enable":"Disable"})," feature toggle"," ",o("strong",{children:t})," in ",o("strong",{children:a})]}),Ce=j(he)(({theme:e})=>({color:e.palette.warning.main,fontSize:e.fontSizes.bodySize})),ke=()=>o(ye,{arrow:!0,title:p(fe,{children:["This environment has no variants enabled. If you check this feature's variants in this environment, you will get the"," ",o("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants#the-disabled-variant",target:"_blank",rel:"noreferrer",children:"disabled variant"}),"."]}),children:o(Ce,{})}),xe=({isStale:e,isOpen:t,projectId:a,featureId:n,onClose:s})=>{const{setToastData:r,setToastApiError:i}=S(),{patchFeatureToggle:l}=N(),u=o(b,{children:"Setting a toggle to stale marks it for cleanup"}),g=o(b,{children:"Setting a toggle to active marks it as in active use"}),c=e?"active":"stale",h=async m=>{m.stopPropagation();try{await l(a,n,[{op:"replace",path:"/stale",value:!e}]),s()}catch(T){i(v(T))}r(e?{type:"success",title:"And we're back!",text:"The toggle is no longer marked as stale."}:{type:"success",title:"A job well done.",text:"The toggle has been marked as stale."})};return o(C,{open:t,secondaryButtonText:"Cancel",primaryButtonText:`Flip to ${c}`,title:`Set feature state to ${c}`,onClick:h,onClose:s,children:o(w,{condition:e,show:g,elseShow:u})})},De=({isOpen:e,onClose:t,onConfirm:a,projectId:n,featureId:s})=>{const{archiveFeatureToggle:r}=N(),{setToastData:i,setToastApiError:l}=S(),u=async()=>{try{await r(n,s),i({text:"Your feature toggle has been archived",type:"success",title:"Feature archived"}),a(),t()}catch(g){l(v(g)),t()}};return o(C,{onClick:()=>u(),open:e,onClose:t,primaryButtonText:"Archive toggle",secondaryButtonText:"Cancel",title:"Archive feature toggle",children:"Are you sure you want to archive this feature toggle?"})};export{Re as C,Ee as E,Ae as F,qe as U,ke as V,we as a,De as b,xe as c,Te as f,Fe as u};
|
package/frontend/build/static/{FeatureMetricsChart-86cc2280.js → FeatureMetricsChart-1e05efb3.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c7 as i,eZ as p,bu as y,r as l,j as u}from"./index-
|
|
1
|
+
import{c7 as i,eZ as p,bu as y,r as l,j as u}from"./index-e6748c1b.js";import{d,L as g,C as h,a as C,b as f,P as x,c as S,T as q,p as M,e as k,f as L}from"./chartjs-adapter-date-fns.esm-f7b23ba0.js";import"./index-cae4a71b.js";import"./index-bde9bd95.js";const P=(t,s)=>{const o={label:"total requests",borderColor:i.palette.primary.main,backgroundColor:i.palette.primary.main,data:n(t,s,r=>r.yes+r.no),elements:{point:{radius:6,pointStyle:"circle"},line:{borderDash:[8,4]}}},e={label:"exposed",borderColor:i.palette.success.main,backgroundColor:i.palette.success.main,data:n(t,s,r=>r.yes),elements:{point:{radius:6,pointStyle:"triangle"}}},a={label:"not exposed",borderColor:i.palette.error.main,backgroundColor:i.palette.error.main,data:n(t,s,r=>r.no),elements:{point:{radius:6,pointStyle:"triangle",pointRotation:180}}};return{datasets:[e,a,o]}},n=(t,s,o)=>t.map(e=>({x:e.timestamp,y:o(e)})),v=(t,s,o)=>({locale:o.locale,responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{tooltip:{backgroundColor:"white",bodyColor:i.palette.text.primary,titleColor:i.palette.grey[700],borderColor:i.palette.primary.main,borderWidth:1,padding:10,boxPadding:5,usePointStyle:!0,callbacks:{title:e=>p(e[0].parsed.x,o.locale)},itemSort:(e,a)=>a.parsed.y-e.parsed.y},legend:{position:"top",align:"end",labels:{boxWidth:10,boxHeight:10,usePointStyle:!0}},title:{text:w(s),position:"top",align:"start",display:!0,font:{size:16,weight:"400"}}},scales:{y:{type:"linear",title:{display:!0,text:"Number of requests"},suggestedMin:0,ticks:{precision:0}},x:{type:"time",time:{unit:"hour"},grid:{display:!1},ticks:{callback:(e,a,r)=>p(r[a].value,o.locale)}}}}),w=t=>t===1?"Requests in the last hour":`Requests in the last ${t} hours`;d.font={...d.font,family:"Sen",size:13,weight:"400"};const j=({metrics:t,hoursBack:s,statsSectionId:o})=>{const{locationSettings:e}=y(),a=l.useMemo(()=>[...t].sort((m,b)=>m.timestamp.localeCompare(b.timestamp)),[t]),r=l.useMemo(()=>v(a,s,e),[a,s,e]),c=l.useMemo(()=>P(a,e),[a,e]);return u("div",{style:{height:400},children:u(g,{options:r,data:c,"aria-label":"A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.","aria-describedby":o})})};h.register(C,f,x,S,q,M,k,L);export{j as FeatureMetricsChart,j as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{az as vn,aA as wn,s as d,r as m,aB as Tn,aC as xn,aD as pt,j as t,aE as An,aF as En,c as ke,aG as F,aH as _,aI as In,f as l,aJ as Rn,C as E,aK as K,aL as se,aM as X,aN as fe,aO as Fn,aP as et,aQ as ue,aR as Se,aS as Pe,u as be,aT as ae,F as O,aU as gt,aV as ht,aW as tt,aX as oe,aY as ie,T as M,aZ as Ce,a2 as U,ar as pe,a_ as nt,a$ as ve,A as ge,b0 as _t,a4 as N,b1 as kn,b2 as Pn,b3 as $n,b4 as Bn,ap as we,b5 as On,b6 as le,b7 as Z,m as $e,b8 as Dn,b9 as Vn,ba as Be,a8 as Oe,bb as jt,bc as Nt,bd as at,be as Ln,bf as Mn,bg as _n,a as q,p as jn,N as ce,B as Ye,bh as ot,a9 as re,bi as Nn,x as rt,an as Ee,E as zn,bj as st,bk as Ie,P as Wn,bl as Hn,bm as ee,bn as qn,bo as Un,D as Gn,bp as Yn,bq as Kn,br as Xn,bs as zt,bt as Jn,w as De,bu as Qn,bv as Zn,bw as ea,bx as ta,by as na,bz as Te,bA as aa,bB as oa,bC as ra,bD as Wt,ad as it,ac as Ve,bE as Ht,bF as qt,bG as sa,bH as ia,bI as la,bJ as ca,Z as da,bK as Ut,bL as ua,af as Re,bM as pa,bN as Ke,bO as Gt,bP as Yt,bQ as ne,bR as Xe,bS as ga,bT as Kt,a3 as lt,bU as ha,bV as Xt,bW as ma,bX as fa,bY as Jt,bZ as Qt,H as ct,au as ya,b_ as he,b$ as mt,c0 as Sa,c1 as Zt,l as te,c2 as Je,c3 as en,R as ba,b as Ca,Q as va,d as me,e as wa,U as tn,X as Ta,g as nn,S as an,h as on,i as rn,k as sn,W as xa,c4 as Aa,ak as dt,al as Ea,V as ft,c5 as Ia,c6 as Ra,c7 as ln,I as Fa,c8 as ka,c9 as Pa,ca as yt,cb as $a,cc as cn,cd as Ba,ae as Oa,ce as St,cf as Da,cg as Va,ch as La,ci as Ma,cj as _a,ck as ja,M as Na,cl as za,cm as Wa,cn as Ha,co as qa,cp as Ua,cq as Ga}from"./index-193ec8c2.js";import{C as Le,f as Ya,u as Ka,U as Xa,E as Ja,V as Qa,a as Za,F as eo,b as to,c as no}from"./FeatureArchiveDialog-f9d8c71d.js";import{S as ao}from"./StrategyItemContainer-b65caaa6.js";import{E as oo}from"./ExpandMore-4b3cbf87.js";import{v as je}from"./v4-a960c1f4.js";function ro(e){return vn("MuiCardContent",e)}wn("MuiCardContent",["root"]);const so=["className","component"],io=e=>{const{classes:n}=e;return En({root:["root"]},ro,n)},lo=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),co=m.forwardRef(function(n,a){const r=Tn({props:n,name:"MuiCardContent"}),{className:o,component:s="div"}=r,i=xn(r,so),c=pt({},r,{component:s}),u=io(c);return t(lo,pt({as:s,className:An(u.root,o),ownerState:c,ref:a},i))}),uo=co,po=ke(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),go=ke(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),ho=ke(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),mo=ke(t("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm4.2 14.2L11 13V7h1.5v5.2l4.5 2.7-.8 1.3z"}),"WatchLater"),fo=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),yo=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n);return a.name?t(fo,{children:t(In,{title:"Event log",feature:n,displayInline:!0})}):null},So=d("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.text.tertiaryContrast,backgroundColor:e.palette.featureMetaData,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),bo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Co=d("div")({display:"flex",alignItems:"center"}),vo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),wo=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),bt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),Ct=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.text.tertiaryContrast})),To=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n),{project:r,description:o,type:s}=a,i=Fn(s);return t(So,{children:l(bo,{children:[l(Co,{"data-loading":!0,children:[t(i,{sx:c=>({marginRight:c.spacing(2),height:"40px",width:"40px",fill:c.palette.text.tertiaryContrast})})," ",l(vo,{children:[Rn(s||"")," toggle"]})]}),l(wo,{children:[l(bt,{"data-loading":!0,children:["Project: ",r]}),t(E,{condition:Boolean(o),show:l(bt,{"data-loading":!0,children:[t("div",{children:"Description:"}),l(Ct,{children:[t("p",{children:o}),t(K,{projectId:e,permission:se,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(fe,{sx:c=>({color:c.palette.text.tertiaryContrast})})})]})]}),elseShow:t("span",{"data-loading":!0,children:l(Ct,{children:["No description."," ",t(K,{projectId:e,permission:se,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(fe,{sx:c=>({color:c.palette.text.tertiaryContrast})})})]})})})]})]})})},vt={lastHourUsage:[],seenApplications:[]},xo=(e,n,a={})=>{const r=async()=>{const g=ue(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Se("feature metrics"));return h.ok?h.json():vt},o=`${e}_${n}_metrics`,{data:s,error:i}=et(o,r,{...a}),[c,u]=m.useState(!i&&!s),p=()=>{Pe(o)};return m.useEffect(()=>{u(!i&&!s)},[s,i]),{metrics:s||vt,error:i,loading:c,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},Ao=e=>({yes:0,no:0,environment:e,timestamp:""}),Eo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||Ao(a.name)),Io=({enabled:e,className:n})=>{const a=be(),r=e?"Environment enabled":"Environment disabled",o={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)};return t("div",{style:o,className:n,children:t(ho,{style:{fill:"#fff",width:"16px",height:"16px"},titleAccess:r})})},dn=()=>t(ge,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Ro=({onRemove:e,onClose:n,isOpen:a})=>t(ie,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(dn,{})}),Fo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),ko=({onRemove:e,onClose:n,isOpen:a})=>l(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(dn,{}),t(Fo,{children:t(M,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(M,{fontWeight:"bold",children:"Remove strategy"})]}),Po=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{deleteStrategyFromFeature:o}=Ce(),{setToastData:s,setToastApiError:i}=U(),c=pe(),{refetchFeature:u}=_(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,r),s({title:"Strategy deleted",type:"success"}),u(),c(_t(e,n))}catch(h){i(N(h))}}},$o=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{addChange:o}=nt(),{refetch:s}=ve(e),{setToastData:i,setToastApiError:c}=U();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:r}}),i({title:"Changes added to the draft!",type:"success"}),await s()}catch(g){c(N(g))}}},Bo=({projectId:e,featureId:n,environmentId:a,strategyId:r,disabled:o,icon:s})=>{const[i,c]=m.useState(!1),{isChangeRequestConfigured:u}=ae(e),p=Po({featureId:n,projectId:e,strategyId:r,environmentId:a}),g=$o({featureId:n,projectId:e,strategyId:r,environmentId:a});return l(O,{children:[t(E,{condition:Boolean(s),show:t(K,{onClick:()=>c(!0),projectId:e,environmentId:a,disabled:o,permission:gt,"data-testid":ht,tooltipProps:{title:"Remove strategy"},type:"button",children:t(tt,{})}),elseShow:t(oe,{onClick:()=>c(!0),projectId:e,environmentId:a,disabled:o,permission:gt,"data-testid":ht,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(E,{condition:u(a),show:t(ko,{isOpen:i,onClose:()=>c(!1),onRemove:async h=>{await g(h),c(!1)}}),elseShow:t(Ro,{isOpen:i,onClose:()=>c(!1),onRemove:p})})]})},Oo=e=>(n,a,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,a,r));var Do=kn(et,Oo);const un=(e,n)=>{const{refetchFeature:a}=_(e,n),r=Pn(e,n),{data:o,error:s,mutate:i}=Do(["useFeatureImmutable",r],()=>$n(r)),c=m.useCallback(async()=>{await i(),await a()},[i,a]);return{feature:(o==null?void 0:o.body)||Bn,refetchFeature:c,loading:!s&&!o,status:o==null?void 0:o.status,error:s}},ut=(e,n,a)=>{const{setToastData:r,setToastApiError:o}=U(),{addChange:s}=nt(),{refetch:i}=ve(e),[c,u]=m.useState({isOpen:!1}),p=m.useCallback((v,T,f)=>{u({featureName:n,environment:v,fromEnvironment:f,strategy:T,isOpen:!0})},[]),g=m.useCallback((v,T,f)=>{u({featureName:n,environment:v,fromEnvironment:f,strategies:T,isOpen:!0})},[]),h=m.useCallback(()=>{u({isOpen:!1})},[]),b=m.useCallback(async()=>{try{await s(e,c.environment,{feature:c.featureName,action:a,payload:c.strategy}),i(),u({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(v){o(N(v)),u({isOpen:!1})}},[s]),y=m.useCallback(async()=>{try{await Promise.all(c.strategies.map(v=>s(e,c.environment,{feature:c.featureName,action:a,payload:v}))),i(),u({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(v){o(N(v)),u({isOpen:!1})}},[s]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:c}},Vo=({payload:e,fromEnvironment:n,environment:a})=>l(M,{children:[l("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Lo=({environmentId:e,environments:n,strategy:a})=>{const r=F("projectId"),o=F("featureId"),[s,i]=m.useState(null),c=Boolean(s),{addStrategyToFeature:u}=Ce(),{setToastData:p,setToastApiError:g}=U(),{refetchFeature:h}=_(r,o),{refetchFeature:b}=un(r,o),y=()=>{i(null)},v=On(r),{isChangeRequestConfigured:T}=ae(r),{changeRequestDialogDetails:f,onChangeRequestAddStrategyClose:S,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:x}=ut(r,o,"addStrategy"),$=async P=>{const{id:B,...I}={...a,targetEnvironment:P};if(T(P)){await w(P,{id:B,...I},e);return}try{await u(r,o,P,a),h(),b(),p({title:"Strategy created",text:`Successfully copied a strategy to ${P}`,type:"success"})}catch(j){g(N(j))}y()},D=n.some(P=>v(le,P));return l("div",{children:[t(Le,{isOpen:f.isOpen,onClose:S,environment:f==null?void 0:f.environment,onConfirm:x,messageComponent:t(Vo,{fromEnvironment:f.fromEnvironment,payload:f.strategy})}),t(Z,{title:`Copy to another environment${D?"":" (Access denied)"}`,children:t("div",{children:t($e,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:P=>{i(P.currentTarget)},"data-testid":Dn,disabled:!D,children:t(Vn,{})})})}),t(Be,{id:"basic-menu",anchorEl:s,open:c,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(P=>{const B=v(le,P);return t(Z,{title:B?"":"You don't have access to add a strategy to this environment",children:t("div",{children:l(Oe,{onClick:()=>$(P),disabled:!B,children:[t(E,{condition:!B,show:t(jt,{children:t(Nt,{fontSize:"small"})})}),l(at,{children:["Copy to ",P]})]})})},P)})})]})},Mo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:r,otherEnvironments:o,orderNumber:s,headerChildren:i})=>{const c=F("projectId"),u=F("featureId"),p=Ln(c,u,e,n.id);return t(ao,{strategy:n,onDragStart:a,onDragEnd:r,orderNumber:s,actions:l(O,{children:[i,t(E,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(Lo,{environmentId:e,environments:o,strategy:n})}),t(K,{permission:Mn,environmentId:e,projectId:c,component:X,to:p,tooltipProps:{title:"Edit strategy"},children:t(fe,{})}),t(Bo,{projectId:c,featureId:u,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(_n,{strategy:n})})},_o=(e,n,a,r)=>{const{data:o}=ve(e),s=o==null?void 0:o.find(u=>u.environment===a),i=s==null?void 0:s.features.find(u=>u.name===n);return i==null?void 0:i.changes.find(u=>u.action==="updateStrategy"||u.action==="deleteStrategy"?u.payload.id===r:!1)},jo=({strategy:e,index:n,environmentName:a,otherEnvironments:r,isDragging:o,onDragStartRef:s,onDragOver:i,onDragEnd:c})=>{const u=F("projectId"),p=F("featureId"),g=m.useRef(null),h=_o(u,p,a,e.id);return l(q,{ref:g,onDragOver:i(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(jn,{text:"OR"})}),t(Mo,{strategy:e,environmentId:a,otherEnvironments:r,onDragStart:s(g,n),onDragEnd:c,orderNumber:n+1,headerChildren:t(No,{change:h})})]},e.id)},No=({change:e})=>{const n=be();return ce(n.breakpoints.down("sm"))?null:l(q,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Ye,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Ye,{color:"error",children:"Deleted in draft"})})]})},zo=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.dividerAlternative}})),Wo=d("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.secondaryContainer,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),pn=({children:e})=>t(zo,{children:t(Wo,{children:e})}),Ho=({environmentId:e,environments:n,onClick:a})=>{const r=F("projectId"),[o,s]=m.useState(null),i=Boolean(o),{hasAccess:c}=m.useContext(ot),u=n.some(p=>c(le,r,p));return l("div",{children:[t(Z,{title:u?"":"(Access denied)",children:t("div",{children:t(re,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:p=>{s(p.currentTarget)},disabled:!u,variant:"outlined",children:"Copy from another environment"})})}),t(Be,{id:"basic-menu",anchorEl:o,open:i,onClose:()=>{s(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(p=>{const g=c(le,r,p);return t(Z,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:l(Oe,{onClick:()=>a(p),disabled:!g,children:[t(E,{condition:!g,show:t(jt,{children:t(Nt,{fontSize:"small"})})}),l(at,{children:["Copy from ",p]})]})})},p)})})]})},qo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Uo=({payload:e,fromEnvironment:n,environment:a})=>l(qo,{children:[t(M,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>l(M,{children:[l("strong",{children:[we((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),l(M,{children:["from ",n," to ",a]})]}),Go=({payload:e,environment:n})=>l(O,{children:[t(M,{component:"span",children:"Add "}),l("strong",{children:[we((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),Yo=d(Nn)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),wt=({title:e,children:n,featureId:a,projectId:r,environmentId:o,strategy:s,Icon:i,onAfterAddStrategy:c})=>{const{addStrategyToFeature:u}=Ce(),{setToastApiError:p}=U(),{isChangeRequestConfigured:g}=ae(r),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:y,onChangeRequestAddStrategyClose:v}=ut(r,a,"addStrategy");return l(O,{children:[t(Yo,{variant:"outlined",children:l(uo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[l(M,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(i,{color:"disabled",sx:{mr:1}})," ",e]}),t(M,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(q,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(oe,{permission:le,projectId:r,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,s):(await u(r,a,o,s),c())}catch(f){p(N(f))}},children:"Use template"})})]})}),t(Le,{isOpen:h.isOpen,onClose:v,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Go,{environment:o,payload:h.strategy})})]})},Ko=d("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),Xo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Jo=d(rt)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Qo=d(X)(({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.dividerAlternative,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),Zo=({projectId:e,featureId:n,environmentId:a,strategy:r})=>{const o=Ee(r.name),s=we(r.name),i=Ya(e,n,a,r.name);return l(Qo,{to:i,children:[t(Ko,{children:t(o,{})}),l("div",{children:[t(Jo,{text:r.displayName||s,maxWidth:"200",maxLength:25}),t(Xo,{children:r.description})]})]})},er=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:r}=zn(),o=m.useMemo(()=>r.filter(s=>!s.deprecated),[r]);return t(st,{dense:!0,children:o.map(s=>t(Ie,{children:t(Zo,{projectId:e,featureId:n,environmentId:a,strategy:s})},s.name))})},Qe=({label:e,projectId:n,featureId:a,environmentId:r,variant:o,matchWidth:s})=>{const[i,c]=m.useState(),u=Boolean(i),p=u?"FeatureStrategyMenuPopover":void 0,g=()=>{c(void 0)};return l("div",{onClick:b=>b.stopPropagation(),children:[t(oe,{permission:le,projectId:n,environmentId:r,onClick:b=>{c(b.currentTarget)},"aria-labelledby":p,variant:o,sx:{minWidth:s?"282px":"auto"},children:e}),t(Wn,{id:p,open:u,anchorEl:i,onClose:g,onClick:g,children:t(er,{projectId:n,featureId:a,environmentId:r})})]})},tr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),nr=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),ar=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3)})),or=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:r}=Ce(),{setToastData:o,setToastApiError:s}=U(),{refetchFeature:i}=_(e,n),{refetchFeature:c}=un(e,n),{feature:u}=_(e,n),p=u==null?void 0:u.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:g}=ae(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:y,onChangeRequestAddStrategyClose:v}=ut(e,n,"addStrategy"),T=(w=!1)=>{i(),c(),o({title:w?"Strategies created":"Strategy created",text:w?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},f=async w=>{var $;const x=(($=p==null?void 0:p.find(D=>D.name===w))==null?void 0:$.strategies)||[];if(g(a)){await b(a,x,w);return}try{await Promise.all(x.map(D=>{const{id:P,...B}={...D,environment:a};return r(e,n,a,B)})),T(!0)}catch(D){s(N(D))}},S=p&&p.length>0;return l(O,{children:[t(Le,{isOpen:h.isOpen,onClose:v,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Uo,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),l(tr,{children:[t(nr,{children:"You have not defined any strategies yet."}),l(ar,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),l(q,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(Qe,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:S}),t(E,{condition:S,show:t(Ho,{environmentId:a,environments:p.map(w=>w.name),onClick:f})})]}),t(q,{sx:{width:"100%",mt:3},children:t(pn,{children:"Or use a strategy template"})}),l(q,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(wt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:T,Icon:Ee("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(wt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:T,Icon:Ee("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:u.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},rr=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),sr=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ir=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const r=F("projectId"),o=F("featureId"),{setStrategiesSortOrder:s}=Ce(),{setToastData:i,setToastApiError:c}=U(),{refetchFeature:u}=_(r,o),[p,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,b]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const y=async S=>{try{await s(r,o,e.name,S),u(),i({title:"Order of strategies updated",type:"success"})}catch(w){c(N(w))}},v=(S,w)=>x=>{var $;b({id:p[w].id,index:w,height:(($=S.current)==null?void 0:$.offsetHeight)||0}),S!=null&&S.current&&(x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/html",S.current.outerHTML),x.dataTransfer.setDragImage(S.current,20,20))},T=S=>(w,x)=>$=>{if(h===null||w.current===null||h.index===x||S===h.id)return;const{top:D,bottom:P}=w.current.getBoundingClientRect(),B=$.clientY-D<h.height,I=P-$.clientY<h.height,j=h.index>x;if(B&&j||I&&!j){const z=[...p],L=z.splice(h.index,1)[0];z.splice(x,0,L),g(z),b({...h,index:x})}},f=()=>{b(null),y(p.map((S,w)=>({id:S.id,sortOrder:w})))};return t(rr,{children:l(sr,{children:[t(E,{condition:p.length>0&&n,show:()=>t(ge,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:p.length>0,show:t(O,{children:p.map((S,w)=>t(jo,{strategy:S,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===S.id,onDragStartRef:v,onDragOver:T(S.id),onDragEnd:f},S.id))}),elseShow:t(or,{projectId:r,featureId:o,environmentId:e.name})})]})})},gn=(e,n)=>e===0?0:Math.round(n/e*100);var Me={},_e={};Object.defineProperty(_e,"__esModule",{value:!0});_e.defaultOptions=void 0;_e.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var de={};Object.defineProperty(de,"__esModule",{value:!0});de.roundTo=de.parseValue=void 0;function lr(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}de.parseValue=lr;function cr(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}de.roundTo=cr;Object.defineProperty(Me,"__esModule",{value:!0});Me.millify=void 0;const Ne=_e,Tt=de,xt=1e3;function*At(e){let n=xt;for(;;){const a=e/n;if(a<1)return;yield a,n*=xt}}function hn(e,n){var a;const r=n?Object.assign(Object.assign({},Ne.defaultOptions),n):Ne.defaultOptions;if(!Array.isArray(r.units)||!r.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Tt.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const s=o<0?"-":"";o=Math.abs(o);let i=0;for(const y of At(o))o=y,i+=1;if(i>=r.units.length)return e.toString();let u=Tt.roundTo(o,r.precision);for(const y of At(u))u=y,i+=1;const p=(a=r.units[i])!==null&&a!==void 0?a:"",g=r.lowercase?p.toLowerCase():p,h=r.space?" ":"",b=u.toString().replace(Ne.defaultOptions.decimalSeparator,r.decimalSeparator);return`${s}${b}${h}${g}`}Me.millify=hn;var dr=Me.default=hn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let r,o=!1;e<n?r=e.toLocaleString():(r=dr(e,{precision:a}),o=!0);const s=t("span",{"data-testid":Hn,children:r});return t(E,{condition:o,show:t(Z,{title:e.toLocaleString(),arrow:!0,children:s}),elseShow:s})},ze=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),We=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),He=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),qe=d("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.dividerAlternative,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),mn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:r,tableSectionId:o})=>{const s=a===1?"in the last hour":`in the last ${a} hours`;return l(ee,{container:!0,spacing:2,id:r,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Exposure"}),t(He,{children:t(Fe,{value:e})}),l(qe,{children:["Total exposure of the feature in the environment"," ",s,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Exposure %"}),l(He,{children:[gn(e+n,e),"%"]}),l(qe,{children:["% total exposure of the feature in the environment"," ",s,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Requests"}),t(He,{children:t(Fe,{value:e+n})}),l(qe,{children:["Total requests for the feature in the environment"," ",s,"."]})]})})]})},ur=({environmentMetric:e})=>e?l(O,{children:[t(pn,{children:"Feature toggle exposure"}),t("div",{children:t(mn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Et=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),It=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Rt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Ft=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),pr=d(qn)(({theme:e})=>({fill:e.palette.standaloneBackground,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),gr=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),hr=({environmentMetric:e,disabled:n=!1})=>{const a=Un();if(!e)return null;const r=e.yes+e.no,o=gn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?l(Et,{children:[l(It,{children:[l(Rt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),l(Ft,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(pr,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):l(Et,{children:[l(It,{children:[l(Rt,{children:[o,"%"]}),l(Ft,{children:["The feature has been requested"," ",l("b",{children:[t(Fe,{value:r})," times"]})," ","and exposed"," ",l("b",{children:[t(Fe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(gr,{"data-loading":!0,children:t(Gn,{percentage:o,size:"3rem"})})]})},mr=({strategyName:e})=>{const n=Ee(e);return t(Z,{title:we(e),arrow:!0,children:t(fr,{children:t(n,{})})})},fr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.inactiveIcon,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),yr=({strategies:e})=>e!=null&&e.length?t(Sr,{"aria-label":"Feature strategies",children:e.map(n=>t(br,{children:t(mr,{strategyName:n.name})},n.id))}):null,Sr=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),br=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Cr=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:e.palette.background.paper,background:n?e.palette.background.paper:e.palette.neutral.light})),vr=d(Yn)({boxShadow:"none",background:"none"}),wr=d(Kn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Tr=d(Xn,{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({padding:e.spacing(3),background:e.palette.secondaryContainer,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,borderBottom:`4px solid ${n?e.palette.primary.light:e.palette.neutral.border}`,[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),xr=d(ir)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ar=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:n?e.palette.text.primary:e.palette.text.secondary})),Er=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Ir=d(Io)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Rr=d(rt)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Fr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),kr=({env:e})=>{var p;const n=F("projectId"),a=F("featureId"),{metrics:r}=xo(n,a),{feature:o}=_(n,a),{value:s}=zt(),c=Eo(o==null?void 0:o.environments,r).find(g=>g.environment===e.name),u=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!Boolean(new Set(s.hiddenEnvironments).has(e.name)),show:t(Cr,{enabled:e.enabled,children:l(vr,{"data-testid":`${Jn}_${e.name}`,children:[l(wr,{expandIcon:t(oo,{titleAccess:"Toggle"}),children:[l(Ar,{"data-loading":!0,enabled:e.enabled,children:[l(Er,{children:[t(Ir,{enabled:e.enabled}),t("div",{children:t(Rr,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(De,{size:"small",variant:"outlined",label:"Disabled",sx:{ml:1}})})]}),l(Fr,{children:[t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(yr,{strategies:u==null?void 0:u.strategies})]})]}),t(hr,{environmentMetric:c,disabled:!e.enabled})]}),l(Tr,{enabled:e.enabled,children:[t(xr,{featureEnvironment:u,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((p=u==null?void 0:u.strategies)==null?void 0:p.length)||0)>0,show:l(O,{children:[t(q,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(ur,{environmentMetric:c})]})})]})]})})})},Pr=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n);if(!a)return null;const{environments:r}=a;return t(O,{children:r==null?void 0:r.map(o=>t(kr,{env:o},o.name))})},$r=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Br=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Or=({feature:e,header:n})=>{const{locationSettings:a}=Qn();return l($r,{children:[n,l("div",{"data-loading":!0,children:[t(Br,{children:"Created at:"}),t("span",{children:Zn(ea(e.createdAt),a.locale)})]})]})},Dr=d($e,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.neutral.main:e.palette.tertiary.main,"&:hover":{color:e.palette.neutral.main}})),Vr=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Dr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(ta,{}),elseShow:t(na,{})})}),Lr=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Mr=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),_r=({environment:e,callback:n,showInfoBox:a,children:r,hiddenEnvironments:o,setHiddenEnvironments:s})=>{const{name:i,enabled:c}=e,u=F("projectId"),p=F("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=Te(),{refetchFeature:b}=_(u,p),{setToastData:y,setToastApiError:v}=U(),{isChangeRequestConfigured:T}=ae(u),{onChangeRequestToggle:f,onChangeRequestToggleClose:S,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:x}=Ka(u),$=async()=>{try{await g(u,p,i),y({type:"success",title:`Available in ${i}`,text:`${p} is now available in ${i} based on its defined strategies.`}),b(),n&&n()}catch(I){I instanceof Error&&I.message===Ja?a():v(N(I))}},D=async()=>{try{await h(u,p,i),y({type:"success",title:`Unavailable in ${i}`,text:`${p} is unavailable in ${i} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(I){v(N(I))}},P=async I=>{if(T(i)){I.preventDefault(),f(p,i,!c);return}if(c){await D();return}await $()},B=l(O,{children:[" ",l("span",{"data-loading":!0,children:[c?"enabled":"disabled"," in"]})," ",t(rt,{text:i,maxWidth:"120",maxLength:15})]});return l(Lr,{children:[l(Mr,{children:[t(aa,{tooltip:c?`Disable feature in ${i}`:`Enable feature in ${i}`,permission:oa,projectId:u,checked:c,onChange:P,environmentId:i}),r??B]}),t(Vr,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:s}),t(Le,{isOpen:x.isOpen,onClose:S,environment:x==null?void 0:x.environment,onConfirm:w,messageComponent:t(Xa,{enabled:x==null?void 0:x.enabled,featureName:x==null?void 0:x.featureName,environment:x.environment})})]})},jr=d("div")(({theme:e})=>({padding:e.spacing(3)})),Nr=d("div")(()=>({display:"flex",flexDirection:"column"})),zr=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Wr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),kt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Hr=d(ra)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),qr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:r})=>{const[o,s]=m.useState(!1),[i,c]=m.useState(""),u=e.environments.some(p=>{var g;return p.enabled&&((g=p.variants)==null?void 0:g.length)});return l(jr,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const g=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,h=p.variants??[],b=h.length>0&&l(O,{children:[t(kt,{}),t(Z,{title:"View variants",arrow:!0,describeChild:!0,children:t(Hr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),y=p.enabled&&h.length===0&&u;return t(_r,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:r,showInfoBox:()=>{c(p.name),s(!0)},children:l(Nr,{children:[t(zr,{children:p.name}),l(Wr,{children:[g,b,t(E,{condition:y,show:l(O,{children:[t(kt,{}),t(Qa,{})]})})]})]})},p.name)}),t(Za,{open:o,onClose:()=>s(!1),projectId:e.project,featureId:e.name,environmentName:i})]})},fn=(e,n={})=>{const a=async()=>{const p=ue(`api/admin/features/${e}/tags`);return(await fetch(p,{method:"GET"}).then(Se("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:o,error:s}=Wt(Boolean(e),{tags:[]},r,a,n),[i,c]=m.useState(!s&&!o),u=()=>{Pe(r)};return m.useEffect(()=>{c(!s&&!o)},[o,s]),{tags:(o==null?void 0:o.tags)||[],error:s,loading:i,refetch:u}},Ur=sa(),Gr=({options:e,featureTags:n,tagType:a,onChange:r})=>{const o=t(ia,{fontSize:"small"}),s=t(la,{fontSize:"small"});return t(it,{multiple:!0,id:"checkboxes-tags-demo",sx:{marginTop:g=>g.spacing(2),width:500},disableCloseOnSelect:!0,placeholder:"Select Values",options:e,isOptionEqualToValue:(g,h)=>h.inputValue&&h.inputValue!==""?g.title===h.inputValue:g.title===h.title,getOptionDisabled:g=>n.some(h=>h.type===a&&h.value===g.title),getOptionLabel:g=>g.inputValue?g.inputValue:g.title,renderOption:(g,h,{selected:b})=>{const y=n.some(v=>v.type===a&&v.value===h.title);return l("li",{...g,children:[t(E,{condition:Boolean(h.inputValue),show:t(Ht,{sx:{mr:v=>v.spacing(.5)}}),elseShow:t(qt,{icon:o,checkedIcon:s,sx:{mr:v=>v.spacing(.5)},checked:b||y})}),h.title]})},filterOptions:(g,h)=>{const b=Ur(g,h),{inputValue:y}=h,v=g.some(T=>y===T.title);return y!==""&&!v&&b.push({inputValue:y,title:`Create new value "${y}"`}),b},ListboxProps:{style:{maxHeight:200,overflow:"auto"}},onChange:r,renderInput:g=>t(Ve,{...g,label:"Select values",placeholder:"Select values"})})},Yr=d("li")({flexDirection:"column"}),Kr=({value:e,onChange:n})=>{const{tagTypes:a}=ca(),r=be();return t(it,{disablePortal:!0,id:"tag-type-select",sx:{marginTop:o=>o.spacing(2),width:500},options:a,disableClearable:!0,value:e,getOptionLabel:o=>o.name,renderOption:(o,s)=>l(Yr,{...o,style:{alignItems:"flex-start",gap:r.spacing(.5)},children:[t(M,{variant:"body1",children:s.name}),t(M,{variant:"caption",children:s.description})]}),renderInput:o=>t(Ve,{...o,label:"Tag type",value:e}),onChange:n,ListboxProps:{style:{maxHeight:200,overflow:"auto"}}})},Xr=()=>{const{makeRequest:e,createRequest:n,errors:a,loading:r}=da({propagateErrors:!0});return{createTag:async s=>{const c=n("api/admin/tags",{method:"POST",body:JSON.stringify(s)});try{return await e(c.caller,c.id)}catch(u){throw u}},errors:a,loading:r}},Jr=(e,n={})=>{const a=async()=>{const p=ue(`api/admin/tags/${e}`);return(await fetch(p,{method:"GET"}).then(Se("Tags"))).json()},r=`api/admin/tags/${e}`,{data:o,error:s}=Wt(Boolean(e),{tags:[]},r,a,n),[i,c]=m.useState(!s&&!o),u=()=>{Pe(r)};return m.useEffect(()=>{c(!s&&!o)},[o,s]),{tags:(o==null?void 0:o.tags)||[],error:s,loading:i,refetch:u}},Qr=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),yn=({open:e,setOpen:n})=>{const a=F("featureId"),{createTag:r}=Xr(),{addTagToFeature:o,loading:s}=Te(),{tags:i,refetch:c}=fn(a),{setToastData:u}=U(),[p,g]=m.useState({name:"simple",description:"Simple tag to get you started",icon:""}),{trackEvent:h}=Ut(),[b,y]=m.useState([]),{tags:v,refetch:T}=Jr(p.name),f=m.useMemo(()=>v.map(B=>({title:B.value})),[v]),S=()=>{n(!1),y([])},w=async B=>{B.preventDefault();let I=0;if(b.length!==0){for(const j of b)if(!i.includes({type:p.name,value:j.title}))try{j.title.startsWith("Create")||(await o(a,{type:p.name,value:j.title}),I++,await c())}catch(z){const L=N(z);u({type:"error",title:"Failed to add tag",text:L,confetti:!1})}I>1&&h("suggest_tags",{props:{eventType:"multiple_tags_added"}}),I>0&&u({type:"success",title:`Added tag${I>1?"s":""} to toggle`,text:`We successfully added ${I} new tag${I>1?"s":""} to your toggle`,confetti:!0}),n(!1),y([])}},x=(B,I)=>{I!=null&&typeof I!="string"&&(B.preventDefault(),g(I))},$=(B,I,j)=>{if(j==="selectOption"){const z=ua(I);I.forEach((L,J)=>{if(typeof L!="string"&&L.inputValue&&L.inputValue!==""){const Q={value:L.inputValue,type:p.name};r(Q).then(()=>{h("suggest_tags",{props:{eventType:"tag_created"}}),T()}),L.title=L.inputValue,L.inputValue="",z[J]=L}}),y(z)}},D=b.length!==0,P="add-tag-form";return t(O,{children:t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:`Add tag (${b.length})`,title:"Add tags to feature toggle",onClick:w,disabledPrimaryButton:s||!D,onClose:S,formId:P,children:l(O,{children:[t(M,{paragraph:!0,sx:{marginBottom:B=>B.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:P,onSubmit:w,children:l(Qr,{children:[t(Kr,{autoFocus:!0,value:p,onChange:x}),t(Gr,{options:f,tagType:p.name,featureTags:i,onChange:$})]})})]})})})},Zr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),es=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),ts=d(De)(({theme:e})=>({fontSize:e.fontSizes.smallBody,".MuiChip-deleteIcon":{color:e.palette.neutral.main}})),ns=d(Re)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),as=d(re)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),os=({feature:e,header:n})=>{const{tags:a,refetch:r}=fn(e.name),{deleteTagFromFeature:o}=Te(),[s,i]=m.useState(!1),[c,u]=m.useState(!1),[p,g]=m.useState(),{setToastData:h,setToastApiError:b}=U(),{hasAccess:y}=m.useContext(ot),v=y(se,e.project),T=async()=>{if(p)try{await o(e.name,p.type,p.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(f){b(N(f))}};return l(Zr,{children:[n,t(es,{children:a.map(f=>{const S=`${f.type}:${f.value}`;return t(ts,{label:S,deleteIcon:t(pa,{titleAccess:"Remove"}),onDelete:v?()=>{u(!0),g(f)}:void 0},S)})}),t(E,{condition:v,show:l(O,{children:[t(E,{condition:a.length>0,show:t(ns,{})}),t(as,{"data-loading":!0,variant:"outlined",startIcon:t(Ht,{}),onClick:()=>i(!0),children:"Add new tag"})]})}),t(yn,{open:s,setOpen:i}),l(ie,{open:c,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{u(!1),g(void 0)},onClick:()=>{u(!1),T(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",l("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},rs=d("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),Ue=d("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),ss=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=F("projectId"),r=F("featureId"),{feature:o}=_(a,r);return l(rs,{children:[t(qr,{header:l(Ue,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:s})=>s).length,")",t(Ke,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:o,hiddenEnvironments:e,setHiddenEnvironments:n}),t(Re,{}),t(Or,{header:t(Ue,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(Re,{}),t(os,{header:t(Ue,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},is=()=>{const{trackEvent:e}=Ut(),{value:n,setValue:a}=zt(),[r,o]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:i=>{a(c=>{const u=new Set(c.hiddenEnvironments);return u.has(i)?(u.delete(i),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(u.add(i),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(u),{...n,hiddenEnvironments:u}})}}},ls=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),cs=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),ds=()=>{const e=pe(),n=F("projectId"),a=F("featureId"),r=_t(n,a),{hiddenEnvironments:o,setHiddenEnvironments:s}=is(),i=()=>e(r);return Gt(a),l(ls,{children:[l("div",{children:[t(To,{}),t(ss,{hiddenEnvironments:o,setHiddenEnvironments:s})]}),t(cs,{children:t(Pr,{})}),l(Yt,{children:[t(ne,{path:"strategies/create",element:t(Xe,{label:"Create feature strategy",onClose:i,open:!0,children:t(eo,{})})}),t(ne,{path:"strategies/edit",element:t(Xe,{label:"Edit feature strategy",onClose:i,open:!0,children:t(ga,{})})})]})]})},us=({values:e=[],updateValues:n,placeholder:a="",error:r,...o})=>{const s=c=>{const p=c.target.value.split(/,\s?/).map(g=>g.trim());n(p)},i=c=>{if(c.key==="Backspace"){const u=c.target.value;if(u.endsWith(", ")){c.preventDefault();const p=u.slice(0,-2);n(p.split(/,\s*/))}}};return t(Ve,{...o,error:r,placeholder:a,value:e?e.join(", "):"",onKeyDown:i,onChange:s,style:{width:"100%"},variant:"outlined",size:"small"})},ps=d("div")(({theme:e})=>({display:"flex",alignItems:"center",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%",alignItems:"flex-start"}}})),gs=d(Kt)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),hs=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),ms=d(us)(()=>({width:"100%"})),fs=d(Ve)(()=>({width:"100%"})),ys=({overrides:e,overridesDispatch:n})=>{const{context:a}=lt(),r=a.map(({name:i})=>({key:i,label:i})),o=i=>c=>{n({type:"UPDATE_VALUES_AT",payload:[i,c]})},s=i=>(c,u)=>{c==null||c.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[i,u||[]]})};return t(O,{children:e.map((i,c)=>{var h;const u=a.find(({name:b})=>b===i.contextName),p=((h=u==null?void 0:u.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=i.values.filter(b=>p.includes(b));return l(ps,{children:[t(gs,{id:"override-context-name",name:"contextName",label:"Context Field",value:i.contextName,options:r,onChange:b=>n({type:"UPDATE_TYPE_AT",payload:[c,b.target.value]})}),l(hs,{children:[t(E,{condition:Boolean(p&&p.length>0),show:t(it,{multiple:!0,id:`override-select-${c}`,isOptionEqualToValue:(b,y)=>b===y,options:p,onChange:s(c),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(fs,{...b,variant:"outlined",label:"Legal values"})}),elseShow:t(ms,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:i.values,updateValues:o(c)})}),t(Z,{title:"Remove",arrow:!0,children:t($e,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:c})},children:t(tt,{})})})]})]},`override=${c}`)})})},Ss=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((i,c)=>c!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((i,c)=>c===a?{...i,values:r}:i);case"UPDATE_TYPE_AT":const[o,s]=n.payload;return e.map((i,c)=>c===o?{...i,contextName:s}:i)}},bs=(e=[])=>m.useReducer(Ss,e);var Y=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Y||{});const Cs=d("div")(({theme:e})=>({position:"relative",backgroundColor:e.palette.neutral.light,display:"flex",flexDirection:"column",padding:e.spacing(3),marginBottom:e.spacing(3),borderRadius:e.shape.borderRadiusLarge})),vs=d(Z)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Sn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Pt=d(Sn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),ws=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),Ts=d(ha)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),$t=d(Xt)(()=>({width:"100%"})),xs=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),As=d(Xt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Es=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),bn=d("div")(({theme:e})=>({display:"flex",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%"}}})),Is=d(bn)({alignItems:"end",justifyContent:"space-between"}),Rs=d(Kt)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),Fs=d(re)(({theme:e})=>({width:e.spacing(20),maxWidth:"100%"})),ks=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Ps={type:"string",value:""},$s=({variant:e,variants:n,updateVariant:a,removeVariant:r,apiPayload:o})=>{const[s,i]=m.useState(e.name),[c,u]=m.useState(e.weightType===Y.FIX),[p,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||Ps),[y,v]=bs(e.overrides||[]),{context:T}=lt(),[f,S]=m.useState({}),w=C=>{S(A=>({...A,[C]:void 0}))},x=(C,A)=>{S(V=>({...V,[C]:A}))};m.useEffect(()=>{var C;w("percentage"),(C=o.error)!=null&&C.includes("%")&&x("percentage","Total weight must equal 100%")},[o.error]);const $=!e.new,D=n.filter(({id:C,weightType:A})=>C!==e.id&&A===Y.VARIABLE).length>0,P=C=>{const A=C.weightType===Y.VARIABLE,V=n.some(k=>k.weightType===Y.FIX),W=n.filter(k=>k.weightType===Y.VARIABLE).length===1;return V&&W&&A},B=C=>{w("name"),J(C,e.id)||x("name","A variant with that name already exists for this environment."),i(C)},I=C=>{(C===""||Q(C))&&g(C)},j=C=>{R(C)||x("payload","Invalid JSON.")},z=()=>{T.length>0&&v({type:"ADD",payload:{contextName:T[0].name,values:[]}})},L=C=>Boolean(C.length),J=(C,A)=>$||!n.some(V=>V.name===C&&V.id!==A),Q=C=>{if(!c)return!0;if(C===""||C.match(/\.[0-9]{2,}$/))return!1;const A=Number(C);return A>=0&&A<=100},R=C=>{try{return C.type==="json"&&JSON.parse(C.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:s,weight:Number(c?p:100)*10,weightType:c?Y.FIX:Y.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:y.map(C=>({contextName:C.contextName,values:C.values})).filter(C=>C.values&&C.values.length>0),isValid:L(s)&&J(s,e.id)&&Q(p)&&R(h)&&!o.error})},[s,c,p,h,y]),m.useEffect(()=>{c||g(String(e.weight/10))},[e.weight]),l(Cs,{children:[t(vs,{arrow:!0,title:P(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t($e,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>r(e.id),disabled:P(e),children:t(tt,{})})})}),l(Is,{children:[l(Es,{children:[t(Sn,{children:"Variant name"}),t(ws,{children:"This will be used to identify the variant in your code"}),t($t,{"data-testid":"VARIANT_NAME_INPUT",autoFocus:!0,label:"Variant name",error:Boolean(f.name),errorText:f.name,value:s,onChange:C=>B(C.target.value),disabled:$,required:!0})]}),t(E,{condition:D,show:l(xs,{children:[t(Ts,{label:"Custom percentage",control:t(ma,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:c,onChange:C=>u(C.target.checked)})}),t(As,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(f.percentage),errorText:f.percentage,value:p,onChange:C=>I(C.target.value),required:c,disabled:!c,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(fa,{position:"end",children:"%"})}})]})})]}),l(Pt,{children:["Payload",t(Ke,{tooltip:"Passed along with the the variant object."})]}),l(bn,{children:[t(Rs,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:ks,onChange:C=>{w("payload"),b(A=>({...A,type:C.target.value}))}}),t($t,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:C=>{w("payload"),b(A=>({...A,value:C.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>j(h),error:Boolean(f.payload),errorText:f.payload})]}),l(Pt,{children:["Overrides",t(Ke,{tooltip:"Here you can specify which users should get this variant."})]}),t(ys,{overrides:y,overridesDispatch:v}),t(Fs,{onClick:z,variant:"outlined",color:"primary",children:"Add override"})]})},Bs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-1.5),marginBottom:e.spacing(4)})),Os=d(Jt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Ds=d("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Vs=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ls=d(ge)(({theme:e})=>({marginBottom:e.spacing(2)})),Ms=d(ge)(({theme:e})=>({marginTop:e.spacing(4)})),_s=d("div")(({theme:e})=>({display:"flex",flexDirection:"column-reverse"})),js=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Bt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ns=d(Qt)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),zs=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Ws=d(re)(({theme:e})=>({marginLeft:e.spacing(3)})),Hs=({environment:e,open:n,setOpen:a,getApiPayload:r,getCrPayload:o,onConfirm:s})=>{var W;const i=F("projectId"),c=F("featureId"),{uiConfig:u}=ct(),{context:p}=lt(),{isChangeRequestConfigured:g}=ae(i),{data:h}=ve(i),{changeRequestInReviewOrApproved:b,alert:y}=Sa(h),v=(e==null?void 0:e.variants)||[],[T,f]=m.useState([]);m.useEffect(()=>{f(v.length?v.map(k=>({...k,isValid:!0,new:!1,id:je()})):[{name:"",weightType:Y.VARIABLE,weight:0,overrides:[],stickiness:(T==null?void 0:T.length)>0?T[0].stickiness:"default",new:!0,isValid:!1,id:je()}])},[n]);const S=(k,G)=>{f(H=>mt(H.map(xe=>xe.id===G?k:xe),1e3))},w=T.map(({new:k,isValid:G,id:H,...xe})=>xe),x=r(v,w),$=o(w),D=async k=>{k.preventDefault(),s(w)},P=()=>z?`curl --location --request POST '${u.unleashUrl}/api/admin/projects/${i}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
1
|
+
import{az as vn,aA as wn,s as d,r as m,aB as Tn,aC as xn,aD as pt,j as t,aE as An,aF as En,c as ke,aG as F,aH as _,aI as In,f as l,aJ as Rn,C as E,aK as K,aL as se,aM as X,aN as fe,aO as Fn,aP as et,aQ as ue,aR as Se,aS as Pe,u as be,aT as ae,F as O,aU as gt,aV as ht,aW as tt,aX as oe,aY as ie,T as M,aZ as Ce,a2 as U,ar as pe,a_ as nt,a$ as ve,A as ge,b0 as _t,a4 as N,b1 as kn,b2 as Pn,b3 as $n,b4 as Bn,ap as we,b5 as On,b6 as le,b7 as Z,m as $e,b8 as Dn,b9 as Vn,ba as Be,a8 as Oe,bb as jt,bc as Nt,bd as at,be as Ln,bf as Mn,bg as _n,a as q,p as jn,N as ce,B as Ye,bh as ot,a9 as re,bi as Nn,x as rt,an as Ee,E as zn,bj as st,bk as Ie,P as Wn,bl as Hn,bm as ee,bn as qn,bo as Un,D as Gn,bp as Yn,bq as Kn,br as Xn,bs as zt,bt as Jn,w as De,bu as Qn,bv as Zn,bw as ea,bx as ta,by as na,bz as Te,bA as aa,bB as oa,bC as ra,bD as Wt,ad as it,ac as Ve,bE as Ht,bF as qt,bG as sa,bH as ia,bI as la,bJ as ca,Z as da,bK as Ut,bL as ua,af as Re,bM as pa,bN as Ke,bO as Gt,bP as Yt,bQ as ne,bR as Xe,bS as ga,bT as Kt,a3 as lt,bU as ha,bV as Xt,bW as ma,bX as fa,bY as Jt,bZ as Qt,H as ct,au as ya,b_ as he,b$ as mt,c0 as Sa,c1 as Zt,l as te,c2 as Je,c3 as en,R as ba,b as Ca,Q as va,d as me,e as wa,U as tn,X as Ta,g as nn,S as an,h as on,i as rn,k as sn,W as xa,c4 as Aa,ak as dt,al as Ea,V as ft,c5 as Ia,c6 as Ra,c7 as ln,I as Fa,c8 as ka,c9 as Pa,ca as yt,cb as $a,cc as cn,cd as Ba,ae as Oa,ce as St,cf as Da,cg as Va,ch as La,ci as Ma,cj as _a,ck as ja,M as Na,cl as za,cm as Wa,cn as Ha,co as qa,cp as Ua,cq as Ga}from"./index-e6748c1b.js";import{C as Le,f as Ya,u as Ka,U as Xa,E as Ja,V as Qa,a as Za,F as eo,b as to,c as no}from"./FeatureArchiveDialog-72b90a0e.js";import{S as ao}from"./StrategyItemContainer-dd157f67.js";import{E as oo}from"./ExpandMore-fa91a7f3.js";import{v as je}from"./v4-a960c1f4.js";function ro(e){return vn("MuiCardContent",e)}wn("MuiCardContent",["root"]);const so=["className","component"],io=e=>{const{classes:n}=e;return En({root:["root"]},ro,n)},lo=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),co=m.forwardRef(function(n,a){const r=Tn({props:n,name:"MuiCardContent"}),{className:o,component:s="div"}=r,i=xn(r,so),c=pt({},r,{component:s}),u=io(c);return t(lo,pt({as:s,className:An(u.root,o),ownerState:c,ref:a},i))}),uo=co,po=ke(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),go=ke(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),ho=ke(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),mo=ke(t("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm4.2 14.2L11 13V7h1.5v5.2l4.5 2.7-.8 1.3z"}),"WatchLater"),fo=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),yo=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n);return a.name?t(fo,{children:t(In,{title:"Event log",feature:n,displayInline:!0})}):null},So=d("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.text.tertiaryContrast,backgroundColor:e.palette.featureMetaData,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),bo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Co=d("div")({display:"flex",alignItems:"center"}),vo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),wo=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),bt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),Ct=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.text.tertiaryContrast})),To=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n),{project:r,description:o,type:s}=a,i=Fn(s);return t(So,{children:l(bo,{children:[l(Co,{"data-loading":!0,children:[t(i,{sx:c=>({marginRight:c.spacing(2),height:"40px",width:"40px",fill:c.palette.text.tertiaryContrast})})," ",l(vo,{children:[Rn(s||"")," toggle"]})]}),l(wo,{children:[l(bt,{"data-loading":!0,children:["Project: ",r]}),t(E,{condition:Boolean(o),show:l(bt,{"data-loading":!0,children:[t("div",{children:"Description:"}),l(Ct,{children:[t("p",{children:o}),t(K,{projectId:e,permission:se,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(fe,{sx:c=>({color:c.palette.text.tertiaryContrast})})})]})]}),elseShow:t("span",{"data-loading":!0,children:l(Ct,{children:["No description."," ",t(K,{projectId:e,permission:se,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(fe,{sx:c=>({color:c.palette.text.tertiaryContrast})})})]})})})]})]})})},vt={lastHourUsage:[],seenApplications:[]},xo=(e,n,a={})=>{const r=async()=>{const g=ue(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Se("feature metrics"));return h.ok?h.json():vt},o=`${e}_${n}_metrics`,{data:s,error:i}=et(o,r,{...a}),[c,u]=m.useState(!i&&!s),p=()=>{Pe(o)};return m.useEffect(()=>{u(!i&&!s)},[s,i]),{metrics:s||vt,error:i,loading:c,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},Ao=e=>({yes:0,no:0,environment:e,timestamp:""}),Eo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||Ao(a.name)),Io=({enabled:e,className:n})=>{const a=be(),r=e?"Environment enabled":"Environment disabled",o={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)};return t("div",{style:o,className:n,children:t(ho,{style:{fill:"#fff",width:"16px",height:"16px"},titleAccess:r})})},dn=()=>t(ge,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Ro=({onRemove:e,onClose:n,isOpen:a})=>t(ie,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(dn,{})}),Fo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),ko=({onRemove:e,onClose:n,isOpen:a})=>l(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(dn,{}),t(Fo,{children:t(M,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(M,{fontWeight:"bold",children:"Remove strategy"})]}),Po=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{deleteStrategyFromFeature:o}=Ce(),{setToastData:s,setToastApiError:i}=U(),c=pe(),{refetchFeature:u}=_(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,r),s({title:"Strategy deleted",type:"success"}),u(),c(_t(e,n))}catch(h){i(N(h))}}},$o=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{addChange:o}=nt(),{refetch:s}=ve(e),{setToastData:i,setToastApiError:c}=U();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:r}}),i({title:"Changes added to the draft!",type:"success"}),await s()}catch(g){c(N(g))}}},Bo=({projectId:e,featureId:n,environmentId:a,strategyId:r,disabled:o,icon:s})=>{const[i,c]=m.useState(!1),{isChangeRequestConfigured:u}=ae(e),p=Po({featureId:n,projectId:e,strategyId:r,environmentId:a}),g=$o({featureId:n,projectId:e,strategyId:r,environmentId:a});return l(O,{children:[t(E,{condition:Boolean(s),show:t(K,{onClick:()=>c(!0),projectId:e,environmentId:a,disabled:o,permission:gt,"data-testid":ht,tooltipProps:{title:"Remove strategy"},type:"button",children:t(tt,{})}),elseShow:t(oe,{onClick:()=>c(!0),projectId:e,environmentId:a,disabled:o,permission:gt,"data-testid":ht,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(E,{condition:u(a),show:t(ko,{isOpen:i,onClose:()=>c(!1),onRemove:async h=>{await g(h),c(!1)}}),elseShow:t(Ro,{isOpen:i,onClose:()=>c(!1),onRemove:p})})]})},Oo=e=>(n,a,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,a,r));var Do=kn(et,Oo);const un=(e,n)=>{const{refetchFeature:a}=_(e,n),r=Pn(e,n),{data:o,error:s,mutate:i}=Do(["useFeatureImmutable",r],()=>$n(r)),c=m.useCallback(async()=>{await i(),await a()},[i,a]);return{feature:(o==null?void 0:o.body)||Bn,refetchFeature:c,loading:!s&&!o,status:o==null?void 0:o.status,error:s}},ut=(e,n,a)=>{const{setToastData:r,setToastApiError:o}=U(),{addChange:s}=nt(),{refetch:i}=ve(e),[c,u]=m.useState({isOpen:!1}),p=m.useCallback((v,T,f)=>{u({featureName:n,environment:v,fromEnvironment:f,strategy:T,isOpen:!0})},[]),g=m.useCallback((v,T,f)=>{u({featureName:n,environment:v,fromEnvironment:f,strategies:T,isOpen:!0})},[]),h=m.useCallback(()=>{u({isOpen:!1})},[]),b=m.useCallback(async()=>{try{await s(e,c.environment,{feature:c.featureName,action:a,payload:c.strategy}),i(),u({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(v){o(N(v)),u({isOpen:!1})}},[s]),y=m.useCallback(async()=>{try{await Promise.all(c.strategies.map(v=>s(e,c.environment,{feature:c.featureName,action:a,payload:v}))),i(),u({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(v){o(N(v)),u({isOpen:!1})}},[s]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:c}},Vo=({payload:e,fromEnvironment:n,environment:a})=>l(M,{children:[l("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Lo=({environmentId:e,environments:n,strategy:a})=>{const r=F("projectId"),o=F("featureId"),[s,i]=m.useState(null),c=Boolean(s),{addStrategyToFeature:u}=Ce(),{setToastData:p,setToastApiError:g}=U(),{refetchFeature:h}=_(r,o),{refetchFeature:b}=un(r,o),y=()=>{i(null)},v=On(r),{isChangeRequestConfigured:T}=ae(r),{changeRequestDialogDetails:f,onChangeRequestAddStrategyClose:S,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:x}=ut(r,o,"addStrategy"),$=async P=>{const{id:B,...I}={...a,targetEnvironment:P};if(T(P)){await w(P,{id:B,...I},e);return}try{await u(r,o,P,a),h(),b(),p({title:"Strategy created",text:`Successfully copied a strategy to ${P}`,type:"success"})}catch(j){g(N(j))}y()},D=n.some(P=>v(le,P));return l("div",{children:[t(Le,{isOpen:f.isOpen,onClose:S,environment:f==null?void 0:f.environment,onConfirm:x,messageComponent:t(Vo,{fromEnvironment:f.fromEnvironment,payload:f.strategy})}),t(Z,{title:`Copy to another environment${D?"":" (Access denied)"}`,children:t("div",{children:t($e,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:P=>{i(P.currentTarget)},"data-testid":Dn,disabled:!D,children:t(Vn,{})})})}),t(Be,{id:"basic-menu",anchorEl:s,open:c,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(P=>{const B=v(le,P);return t(Z,{title:B?"":"You don't have access to add a strategy to this environment",children:t("div",{children:l(Oe,{onClick:()=>$(P),disabled:!B,children:[t(E,{condition:!B,show:t(jt,{children:t(Nt,{fontSize:"small"})})}),l(at,{children:["Copy to ",P]})]})})},P)})})]})},Mo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:r,otherEnvironments:o,orderNumber:s,headerChildren:i})=>{const c=F("projectId"),u=F("featureId"),p=Ln(c,u,e,n.id);return t(ao,{strategy:n,onDragStart:a,onDragEnd:r,orderNumber:s,actions:l(O,{children:[i,t(E,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(Lo,{environmentId:e,environments:o,strategy:n})}),t(K,{permission:Mn,environmentId:e,projectId:c,component:X,to:p,tooltipProps:{title:"Edit strategy"},children:t(fe,{})}),t(Bo,{projectId:c,featureId:u,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(_n,{strategy:n})})},_o=(e,n,a,r)=>{const{data:o}=ve(e),s=o==null?void 0:o.find(u=>u.environment===a),i=s==null?void 0:s.features.find(u=>u.name===n);return i==null?void 0:i.changes.find(u=>u.action==="updateStrategy"||u.action==="deleteStrategy"?u.payload.id===r:!1)},jo=({strategy:e,index:n,environmentName:a,otherEnvironments:r,isDragging:o,onDragStartRef:s,onDragOver:i,onDragEnd:c})=>{const u=F("projectId"),p=F("featureId"),g=m.useRef(null),h=_o(u,p,a,e.id);return l(q,{ref:g,onDragOver:i(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(jn,{text:"OR"})}),t(Mo,{strategy:e,environmentId:a,otherEnvironments:r,onDragStart:s(g,n),onDragEnd:c,orderNumber:n+1,headerChildren:t(No,{change:h})})]},e.id)},No=({change:e})=>{const n=be();return ce(n.breakpoints.down("sm"))?null:l(q,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Ye,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Ye,{color:"error",children:"Deleted in draft"})})]})},zo=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.dividerAlternative}})),Wo=d("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.secondaryContainer,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),pn=({children:e})=>t(zo,{children:t(Wo,{children:e})}),Ho=({environmentId:e,environments:n,onClick:a})=>{const r=F("projectId"),[o,s]=m.useState(null),i=Boolean(o),{hasAccess:c}=m.useContext(ot),u=n.some(p=>c(le,r,p));return l("div",{children:[t(Z,{title:u?"":"(Access denied)",children:t("div",{children:t(re,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:p=>{s(p.currentTarget)},disabled:!u,variant:"outlined",children:"Copy from another environment"})})}),t(Be,{id:"basic-menu",anchorEl:o,open:i,onClose:()=>{s(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(p=>{const g=c(le,r,p);return t(Z,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:l(Oe,{onClick:()=>a(p),disabled:!g,children:[t(E,{condition:!g,show:t(jt,{children:t(Nt,{fontSize:"small"})})}),l(at,{children:["Copy from ",p]})]})})},p)})})]})},qo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Uo=({payload:e,fromEnvironment:n,environment:a})=>l(qo,{children:[t(M,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>l(M,{children:[l("strong",{children:[we((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),l(M,{children:["from ",n," to ",a]})]}),Go=({payload:e,environment:n})=>l(O,{children:[t(M,{component:"span",children:"Add "}),l("strong",{children:[we((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),Yo=d(Nn)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),wt=({title:e,children:n,featureId:a,projectId:r,environmentId:o,strategy:s,Icon:i,onAfterAddStrategy:c})=>{const{addStrategyToFeature:u}=Ce(),{setToastApiError:p}=U(),{isChangeRequestConfigured:g}=ae(r),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:y,onChangeRequestAddStrategyClose:v}=ut(r,a,"addStrategy");return l(O,{children:[t(Yo,{variant:"outlined",children:l(uo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[l(M,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(i,{color:"disabled",sx:{mr:1}})," ",e]}),t(M,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(q,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(oe,{permission:le,projectId:r,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,s):(await u(r,a,o,s),c())}catch(f){p(N(f))}},children:"Use template"})})]})}),t(Le,{isOpen:h.isOpen,onClose:v,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Go,{environment:o,payload:h.strategy})})]})},Ko=d("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),Xo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Jo=d(rt)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Qo=d(X)(({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.dividerAlternative,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),Zo=({projectId:e,featureId:n,environmentId:a,strategy:r})=>{const o=Ee(r.name),s=we(r.name),i=Ya(e,n,a,r.name);return l(Qo,{to:i,children:[t(Ko,{children:t(o,{})}),l("div",{children:[t(Jo,{text:r.displayName||s,maxWidth:"200",maxLength:25}),t(Xo,{children:r.description})]})]})},er=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:r}=zn(),o=m.useMemo(()=>r.filter(s=>!s.deprecated),[r]);return t(st,{dense:!0,children:o.map(s=>t(Ie,{children:t(Zo,{projectId:e,featureId:n,environmentId:a,strategy:s})},s.name))})},Qe=({label:e,projectId:n,featureId:a,environmentId:r,variant:o,matchWidth:s})=>{const[i,c]=m.useState(),u=Boolean(i),p=u?"FeatureStrategyMenuPopover":void 0,g=()=>{c(void 0)};return l("div",{onClick:b=>b.stopPropagation(),children:[t(oe,{permission:le,projectId:n,environmentId:r,onClick:b=>{c(b.currentTarget)},"aria-labelledby":p,variant:o,sx:{minWidth:s?"282px":"auto"},children:e}),t(Wn,{id:p,open:u,anchorEl:i,onClose:g,onClick:g,children:t(er,{projectId:n,featureId:a,environmentId:r})})]})},tr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),nr=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),ar=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3)})),or=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:r}=Ce(),{setToastData:o,setToastApiError:s}=U(),{refetchFeature:i}=_(e,n),{refetchFeature:c}=un(e,n),{feature:u}=_(e,n),p=u==null?void 0:u.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:g}=ae(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:y,onChangeRequestAddStrategyClose:v}=ut(e,n,"addStrategy"),T=(w=!1)=>{i(),c(),o({title:w?"Strategies created":"Strategy created",text:w?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},f=async w=>{var $;const x=(($=p==null?void 0:p.find(D=>D.name===w))==null?void 0:$.strategies)||[];if(g(a)){await b(a,x,w);return}try{await Promise.all(x.map(D=>{const{id:P,...B}={...D,environment:a};return r(e,n,a,B)})),T(!0)}catch(D){s(N(D))}},S=p&&p.length>0;return l(O,{children:[t(Le,{isOpen:h.isOpen,onClose:v,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Uo,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),l(tr,{children:[t(nr,{children:"You have not defined any strategies yet."}),l(ar,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),l(q,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(Qe,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:S}),t(E,{condition:S,show:t(Ho,{environmentId:a,environments:p.map(w=>w.name),onClick:f})})]}),t(q,{sx:{width:"100%",mt:3},children:t(pn,{children:"Or use a strategy template"})}),l(q,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(wt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:T,Icon:Ee("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(wt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:T,Icon:Ee("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:u.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},rr=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),sr=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ir=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const r=F("projectId"),o=F("featureId"),{setStrategiesSortOrder:s}=Ce(),{setToastData:i,setToastApiError:c}=U(),{refetchFeature:u}=_(r,o),[p,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,b]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const y=async S=>{try{await s(r,o,e.name,S),u(),i({title:"Order of strategies updated",type:"success"})}catch(w){c(N(w))}},v=(S,w)=>x=>{var $;b({id:p[w].id,index:w,height:(($=S.current)==null?void 0:$.offsetHeight)||0}),S!=null&&S.current&&(x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/html",S.current.outerHTML),x.dataTransfer.setDragImage(S.current,20,20))},T=S=>(w,x)=>$=>{if(h===null||w.current===null||h.index===x||S===h.id)return;const{top:D,bottom:P}=w.current.getBoundingClientRect(),B=$.clientY-D<h.height,I=P-$.clientY<h.height,j=h.index>x;if(B&&j||I&&!j){const z=[...p],L=z.splice(h.index,1)[0];z.splice(x,0,L),g(z),b({...h,index:x})}},f=()=>{b(null),y(p.map((S,w)=>({id:S.id,sortOrder:w})))};return t(rr,{children:l(sr,{children:[t(E,{condition:p.length>0&&n,show:()=>t(ge,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:p.length>0,show:t(O,{children:p.map((S,w)=>t(jo,{strategy:S,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===S.id,onDragStartRef:v,onDragOver:T(S.id),onDragEnd:f},S.id))}),elseShow:t(or,{projectId:r,featureId:o,environmentId:e.name})})]})})},gn=(e,n)=>e===0?0:Math.round(n/e*100);var Me={},_e={};Object.defineProperty(_e,"__esModule",{value:!0});_e.defaultOptions=void 0;_e.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var de={};Object.defineProperty(de,"__esModule",{value:!0});de.roundTo=de.parseValue=void 0;function lr(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}de.parseValue=lr;function cr(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}de.roundTo=cr;Object.defineProperty(Me,"__esModule",{value:!0});Me.millify=void 0;const Ne=_e,Tt=de,xt=1e3;function*At(e){let n=xt;for(;;){const a=e/n;if(a<1)return;yield a,n*=xt}}function hn(e,n){var a;const r=n?Object.assign(Object.assign({},Ne.defaultOptions),n):Ne.defaultOptions;if(!Array.isArray(r.units)||!r.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Tt.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const s=o<0?"-":"";o=Math.abs(o);let i=0;for(const y of At(o))o=y,i+=1;if(i>=r.units.length)return e.toString();let u=Tt.roundTo(o,r.precision);for(const y of At(u))u=y,i+=1;const p=(a=r.units[i])!==null&&a!==void 0?a:"",g=r.lowercase?p.toLowerCase():p,h=r.space?" ":"",b=u.toString().replace(Ne.defaultOptions.decimalSeparator,r.decimalSeparator);return`${s}${b}${h}${g}`}Me.millify=hn;var dr=Me.default=hn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let r,o=!1;e<n?r=e.toLocaleString():(r=dr(e,{precision:a}),o=!0);const s=t("span",{"data-testid":Hn,children:r});return t(E,{condition:o,show:t(Z,{title:e.toLocaleString(),arrow:!0,children:s}),elseShow:s})},ze=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),We=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),He=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),qe=d("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.dividerAlternative,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),mn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:r,tableSectionId:o})=>{const s=a===1?"in the last hour":`in the last ${a} hours`;return l(ee,{container:!0,spacing:2,id:r,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Exposure"}),t(He,{children:t(Fe,{value:e})}),l(qe,{children:["Total exposure of the feature in the environment"," ",s,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Exposure %"}),l(He,{children:[gn(e+n,e),"%"]}),l(qe,{children:["% total exposure of the feature in the environment"," ",s,"."]})]})}),t(ee,{item:!0,xs:12,sm:4,children:l(ze,{children:[t(We,{children:"Requests"}),t(He,{children:t(Fe,{value:e+n})}),l(qe,{children:["Total requests for the feature in the environment"," ",s,"."]})]})})]})},ur=({environmentMetric:e})=>e?l(O,{children:[t(pn,{children:"Feature toggle exposure"}),t("div",{children:t(mn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Et=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),It=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Rt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Ft=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),pr=d(qn)(({theme:e})=>({fill:e.palette.standaloneBackground,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),gr=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),hr=({environmentMetric:e,disabled:n=!1})=>{const a=Un();if(!e)return null;const r=e.yes+e.no,o=gn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?l(Et,{children:[l(It,{children:[l(Rt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),l(Ft,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(pr,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):l(Et,{children:[l(It,{children:[l(Rt,{children:[o,"%"]}),l(Ft,{children:["The feature has been requested"," ",l("b",{children:[t(Fe,{value:r})," times"]})," ","and exposed"," ",l("b",{children:[t(Fe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(gr,{"data-loading":!0,children:t(Gn,{percentage:o,size:"3rem"})})]})},mr=({strategyName:e})=>{const n=Ee(e);return t(Z,{title:we(e),arrow:!0,children:t(fr,{children:t(n,{})})})},fr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.inactiveIcon,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),yr=({strategies:e})=>e!=null&&e.length?t(Sr,{"aria-label":"Feature strategies",children:e.map(n=>t(br,{children:t(mr,{strategyName:n.name})},n.id))}):null,Sr=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),br=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Cr=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:e.palette.background.paper,background:n?e.palette.background.paper:e.palette.neutral.light})),vr=d(Yn)({boxShadow:"none",background:"none"}),wr=d(Kn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Tr=d(Xn,{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({padding:e.spacing(3),background:e.palette.secondaryContainer,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,borderBottom:`4px solid ${n?e.palette.primary.light:e.palette.neutral.border}`,[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),xr=d(ir)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ar=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:n?e.palette.text.primary:e.palette.text.secondary})),Er=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Ir=d(Io)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Rr=d(rt)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Fr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),kr=({env:e})=>{var p;const n=F("projectId"),a=F("featureId"),{metrics:r}=xo(n,a),{feature:o}=_(n,a),{value:s}=zt(),c=Eo(o==null?void 0:o.environments,r).find(g=>g.environment===e.name),u=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!Boolean(new Set(s.hiddenEnvironments).has(e.name)),show:t(Cr,{enabled:e.enabled,children:l(vr,{"data-testid":`${Jn}_${e.name}`,children:[l(wr,{expandIcon:t(oo,{titleAccess:"Toggle"}),children:[l(Ar,{"data-loading":!0,enabled:e.enabled,children:[l(Er,{children:[t(Ir,{enabled:e.enabled}),t("div",{children:t(Rr,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(De,{size:"small",variant:"outlined",label:"Disabled",sx:{ml:1}})})]}),l(Fr,{children:[t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(yr,{strategies:u==null?void 0:u.strategies})]})]}),t(hr,{environmentMetric:c,disabled:!e.enabled})]}),l(Tr,{enabled:e.enabled,children:[t(xr,{featureEnvironment:u,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((p=u==null?void 0:u.strategies)==null?void 0:p.length)||0)>0,show:l(O,{children:[t(q,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(ur,{environmentMetric:c})]})})]})]})})})},Pr=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=_(e,n);if(!a)return null;const{environments:r}=a;return t(O,{children:r==null?void 0:r.map(o=>t(kr,{env:o},o.name))})},$r=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Br=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Or=({feature:e,header:n})=>{const{locationSettings:a}=Qn();return l($r,{children:[n,l("div",{"data-loading":!0,children:[t(Br,{children:"Created at:"}),t("span",{children:Zn(ea(e.createdAt),a.locale)})]})]})},Dr=d($e,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.neutral.main:e.palette.tertiary.main,"&:hover":{color:e.palette.neutral.main}})),Vr=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Dr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(ta,{}),elseShow:t(na,{})})}),Lr=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Mr=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),_r=({environment:e,callback:n,showInfoBox:a,children:r,hiddenEnvironments:o,setHiddenEnvironments:s})=>{const{name:i,enabled:c}=e,u=F("projectId"),p=F("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=Te(),{refetchFeature:b}=_(u,p),{setToastData:y,setToastApiError:v}=U(),{isChangeRequestConfigured:T}=ae(u),{onChangeRequestToggle:f,onChangeRequestToggleClose:S,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:x}=Ka(u),$=async()=>{try{await g(u,p,i),y({type:"success",title:`Available in ${i}`,text:`${p} is now available in ${i} based on its defined strategies.`}),b(),n&&n()}catch(I){I instanceof Error&&I.message===Ja?a():v(N(I))}},D=async()=>{try{await h(u,p,i),y({type:"success",title:`Unavailable in ${i}`,text:`${p} is unavailable in ${i} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(I){v(N(I))}},P=async I=>{if(T(i)){I.preventDefault(),f(p,i,!c);return}if(c){await D();return}await $()},B=l(O,{children:[" ",l("span",{"data-loading":!0,children:[c?"enabled":"disabled"," in"]})," ",t(rt,{text:i,maxWidth:"120",maxLength:15})]});return l(Lr,{children:[l(Mr,{children:[t(aa,{tooltip:c?`Disable feature in ${i}`:`Enable feature in ${i}`,permission:oa,projectId:u,checked:c,onChange:P,environmentId:i}),r??B]}),t(Vr,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:s}),t(Le,{isOpen:x.isOpen,onClose:S,environment:x==null?void 0:x.environment,onConfirm:w,messageComponent:t(Xa,{enabled:x==null?void 0:x.enabled,featureName:x==null?void 0:x.featureName,environment:x.environment})})]})},jr=d("div")(({theme:e})=>({padding:e.spacing(3)})),Nr=d("div")(()=>({display:"flex",flexDirection:"column"})),zr=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Wr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),kt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Hr=d(ra)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),qr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:r})=>{const[o,s]=m.useState(!1),[i,c]=m.useState(""),u=e.environments.some(p=>{var g;return p.enabled&&((g=p.variants)==null?void 0:g.length)});return l(jr,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const g=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,h=p.variants??[],b=h.length>0&&l(O,{children:[t(kt,{}),t(Z,{title:"View variants",arrow:!0,describeChild:!0,children:t(Hr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),y=p.enabled&&h.length===0&&u;return t(_r,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:r,showInfoBox:()=>{c(p.name),s(!0)},children:l(Nr,{children:[t(zr,{children:p.name}),l(Wr,{children:[g,b,t(E,{condition:y,show:l(O,{children:[t(kt,{}),t(Qa,{})]})})]})]})},p.name)}),t(Za,{open:o,onClose:()=>s(!1),projectId:e.project,featureId:e.name,environmentName:i})]})},fn=(e,n={})=>{const a=async()=>{const p=ue(`api/admin/features/${e}/tags`);return(await fetch(p,{method:"GET"}).then(Se("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:o,error:s}=Wt(Boolean(e),{tags:[]},r,a,n),[i,c]=m.useState(!s&&!o),u=()=>{Pe(r)};return m.useEffect(()=>{c(!s&&!o)},[o,s]),{tags:(o==null?void 0:o.tags)||[],error:s,loading:i,refetch:u}},Ur=sa(),Gr=({options:e,featureTags:n,tagType:a,onChange:r})=>{const o=t(ia,{fontSize:"small"}),s=t(la,{fontSize:"small"});return t(it,{multiple:!0,id:"checkboxes-tags-demo",sx:{marginTop:g=>g.spacing(2),width:500},disableCloseOnSelect:!0,placeholder:"Select Values",options:e,isOptionEqualToValue:(g,h)=>h.inputValue&&h.inputValue!==""?g.title===h.inputValue:g.title===h.title,getOptionDisabled:g=>n.some(h=>h.type===a&&h.value===g.title),getOptionLabel:g=>g.inputValue?g.inputValue:g.title,renderOption:(g,h,{selected:b})=>{const y=n.some(v=>v.type===a&&v.value===h.title);return l("li",{...g,children:[t(E,{condition:Boolean(h.inputValue),show:t(Ht,{sx:{mr:v=>v.spacing(.5)}}),elseShow:t(qt,{icon:o,checkedIcon:s,sx:{mr:v=>v.spacing(.5)},checked:b||y})}),h.title]})},filterOptions:(g,h)=>{const b=Ur(g,h),{inputValue:y}=h,v=g.some(T=>y===T.title);return y!==""&&!v&&b.push({inputValue:y,title:`Create new value "${y}"`}),b},ListboxProps:{style:{maxHeight:200,overflow:"auto"}},onChange:r,renderInput:g=>t(Ve,{...g,label:"Select values",placeholder:"Select values"})})},Yr=d("li")({flexDirection:"column"}),Kr=({value:e,onChange:n})=>{const{tagTypes:a}=ca(),r=be();return t(it,{disablePortal:!0,id:"tag-type-select",sx:{marginTop:o=>o.spacing(2),width:500},options:a,disableClearable:!0,value:e,getOptionLabel:o=>o.name,renderOption:(o,s)=>l(Yr,{...o,style:{alignItems:"flex-start",gap:r.spacing(.5)},children:[t(M,{variant:"body1",children:s.name}),t(M,{variant:"caption",children:s.description})]}),renderInput:o=>t(Ve,{...o,label:"Tag type",value:e}),onChange:n,ListboxProps:{style:{maxHeight:200,overflow:"auto"}}})},Xr=()=>{const{makeRequest:e,createRequest:n,errors:a,loading:r}=da({propagateErrors:!0});return{createTag:async s=>{const c=n("api/admin/tags",{method:"POST",body:JSON.stringify(s)});try{return await e(c.caller,c.id)}catch(u){throw u}},errors:a,loading:r}},Jr=(e,n={})=>{const a=async()=>{const p=ue(`api/admin/tags/${e}`);return(await fetch(p,{method:"GET"}).then(Se("Tags"))).json()},r=`api/admin/tags/${e}`,{data:o,error:s}=Wt(Boolean(e),{tags:[]},r,a,n),[i,c]=m.useState(!s&&!o),u=()=>{Pe(r)};return m.useEffect(()=>{c(!s&&!o)},[o,s]),{tags:(o==null?void 0:o.tags)||[],error:s,loading:i,refetch:u}},Qr=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),yn=({open:e,setOpen:n})=>{const a=F("featureId"),{createTag:r}=Xr(),{addTagToFeature:o,loading:s}=Te(),{tags:i,refetch:c}=fn(a),{setToastData:u}=U(),[p,g]=m.useState({name:"simple",description:"Simple tag to get you started",icon:""}),{trackEvent:h}=Ut(),[b,y]=m.useState([]),{tags:v,refetch:T}=Jr(p.name),f=m.useMemo(()=>v.map(B=>({title:B.value})),[v]),S=()=>{n(!1),y([])},w=async B=>{B.preventDefault();let I=0;if(b.length!==0){for(const j of b)if(!i.includes({type:p.name,value:j.title}))try{j.title.startsWith("Create")||(await o(a,{type:p.name,value:j.title}),I++,await c())}catch(z){const L=N(z);u({type:"error",title:"Failed to add tag",text:L,confetti:!1})}I>1&&h("suggest_tags",{props:{eventType:"multiple_tags_added"}}),I>0&&u({type:"success",title:`Added tag${I>1?"s":""} to toggle`,text:`We successfully added ${I} new tag${I>1?"s":""} to your toggle`,confetti:!0}),n(!1),y([])}},x=(B,I)=>{I!=null&&typeof I!="string"&&(B.preventDefault(),g(I))},$=(B,I,j)=>{if(j==="selectOption"){const z=ua(I);I.forEach((L,J)=>{if(typeof L!="string"&&L.inputValue&&L.inputValue!==""){const Q={value:L.inputValue,type:p.name};r(Q).then(()=>{h("suggest_tags",{props:{eventType:"tag_created"}}),T()}),L.title=L.inputValue,L.inputValue="",z[J]=L}}),y(z)}},D=b.length!==0,P="add-tag-form";return t(O,{children:t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:`Add tag (${b.length})`,title:"Add tags to feature toggle",onClick:w,disabledPrimaryButton:s||!D,onClose:S,formId:P,children:l(O,{children:[t(M,{paragraph:!0,sx:{marginBottom:B=>B.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:P,onSubmit:w,children:l(Qr,{children:[t(Kr,{autoFocus:!0,value:p,onChange:x}),t(Gr,{options:f,tagType:p.name,featureTags:i,onChange:$})]})})]})})})},Zr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),es=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),ts=d(De)(({theme:e})=>({fontSize:e.fontSizes.smallBody,".MuiChip-deleteIcon":{color:e.palette.neutral.main}})),ns=d(Re)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),as=d(re)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),os=({feature:e,header:n})=>{const{tags:a,refetch:r}=fn(e.name),{deleteTagFromFeature:o}=Te(),[s,i]=m.useState(!1),[c,u]=m.useState(!1),[p,g]=m.useState(),{setToastData:h,setToastApiError:b}=U(),{hasAccess:y}=m.useContext(ot),v=y(se,e.project),T=async()=>{if(p)try{await o(e.name,p.type,p.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(f){b(N(f))}};return l(Zr,{children:[n,t(es,{children:a.map(f=>{const S=`${f.type}:${f.value}`;return t(ts,{label:S,deleteIcon:t(pa,{titleAccess:"Remove"}),onDelete:v?()=>{u(!0),g(f)}:void 0},S)})}),t(E,{condition:v,show:l(O,{children:[t(E,{condition:a.length>0,show:t(ns,{})}),t(as,{"data-loading":!0,variant:"outlined",startIcon:t(Ht,{}),onClick:()=>i(!0),children:"Add new tag"})]})}),t(yn,{open:s,setOpen:i}),l(ie,{open:c,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{u(!1),g(void 0)},onClick:()=>{u(!1),T(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",l("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},rs=d("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),Ue=d("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),ss=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=F("projectId"),r=F("featureId"),{feature:o}=_(a,r);return l(rs,{children:[t(qr,{header:l(Ue,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:s})=>s).length,")",t(Ke,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:o,hiddenEnvironments:e,setHiddenEnvironments:n}),t(Re,{}),t(Or,{header:t(Ue,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(Re,{}),t(os,{header:t(Ue,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},is=()=>{const{trackEvent:e}=Ut(),{value:n,setValue:a}=zt(),[r,o]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:i=>{a(c=>{const u=new Set(c.hiddenEnvironments);return u.has(i)?(u.delete(i),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(u.add(i),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(u),{...n,hiddenEnvironments:u}})}}},ls=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),cs=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),ds=()=>{const e=pe(),n=F("projectId"),a=F("featureId"),r=_t(n,a),{hiddenEnvironments:o,setHiddenEnvironments:s}=is(),i=()=>e(r);return Gt(a),l(ls,{children:[l("div",{children:[t(To,{}),t(ss,{hiddenEnvironments:o,setHiddenEnvironments:s})]}),t(cs,{children:t(Pr,{})}),l(Yt,{children:[t(ne,{path:"strategies/create",element:t(Xe,{label:"Create feature strategy",onClose:i,open:!0,children:t(eo,{})})}),t(ne,{path:"strategies/edit",element:t(Xe,{label:"Edit feature strategy",onClose:i,open:!0,children:t(ga,{})})})]})]})},us=({values:e=[],updateValues:n,placeholder:a="",error:r,...o})=>{const s=c=>{const p=c.target.value.split(/,\s?/).map(g=>g.trim());n(p)},i=c=>{if(c.key==="Backspace"){const u=c.target.value;if(u.endsWith(", ")){c.preventDefault();const p=u.slice(0,-2);n(p.split(/,\s*/))}}};return t(Ve,{...o,error:r,placeholder:a,value:e?e.join(", "):"",onKeyDown:i,onChange:s,style:{width:"100%"},variant:"outlined",size:"small"})},ps=d("div")(({theme:e})=>({display:"flex",alignItems:"center",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%",alignItems:"flex-start"}}})),gs=d(Kt)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),hs=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),ms=d(us)(()=>({width:"100%"})),fs=d(Ve)(()=>({width:"100%"})),ys=({overrides:e,overridesDispatch:n})=>{const{context:a}=lt(),r=a.map(({name:i})=>({key:i,label:i})),o=i=>c=>{n({type:"UPDATE_VALUES_AT",payload:[i,c]})},s=i=>(c,u)=>{c==null||c.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[i,u||[]]})};return t(O,{children:e.map((i,c)=>{var h;const u=a.find(({name:b})=>b===i.contextName),p=((h=u==null?void 0:u.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=i.values.filter(b=>p.includes(b));return l(ps,{children:[t(gs,{id:"override-context-name",name:"contextName",label:"Context Field",value:i.contextName,options:r,onChange:b=>n({type:"UPDATE_TYPE_AT",payload:[c,b.target.value]})}),l(hs,{children:[t(E,{condition:Boolean(p&&p.length>0),show:t(it,{multiple:!0,id:`override-select-${c}`,isOptionEqualToValue:(b,y)=>b===y,options:p,onChange:s(c),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(fs,{...b,variant:"outlined",label:"Legal values"})}),elseShow:t(ms,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:i.values,updateValues:o(c)})}),t(Z,{title:"Remove",arrow:!0,children:t($e,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:c})},children:t(tt,{})})})]})]},`override=${c}`)})})},Ss=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((i,c)=>c!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((i,c)=>c===a?{...i,values:r}:i);case"UPDATE_TYPE_AT":const[o,s]=n.payload;return e.map((i,c)=>c===o?{...i,contextName:s}:i)}},bs=(e=[])=>m.useReducer(Ss,e);var Y=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Y||{});const Cs=d("div")(({theme:e})=>({position:"relative",backgroundColor:e.palette.neutral.light,display:"flex",flexDirection:"column",padding:e.spacing(3),marginBottom:e.spacing(3),borderRadius:e.shape.borderRadiusLarge})),vs=d(Z)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Sn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Pt=d(Sn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),ws=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),Ts=d(ha)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),$t=d(Xt)(()=>({width:"100%"})),xs=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),As=d(Xt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Es=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),bn=d("div")(({theme:e})=>({display:"flex",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%"}}})),Is=d(bn)({alignItems:"end",justifyContent:"space-between"}),Rs=d(Kt)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),Fs=d(re)(({theme:e})=>({width:e.spacing(20),maxWidth:"100%"})),ks=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Ps={type:"string",value:""},$s=({variant:e,variants:n,updateVariant:a,removeVariant:r,apiPayload:o})=>{const[s,i]=m.useState(e.name),[c,u]=m.useState(e.weightType===Y.FIX),[p,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||Ps),[y,v]=bs(e.overrides||[]),{context:T}=lt(),[f,S]=m.useState({}),w=C=>{S(A=>({...A,[C]:void 0}))},x=(C,A)=>{S(V=>({...V,[C]:A}))};m.useEffect(()=>{var C;w("percentage"),(C=o.error)!=null&&C.includes("%")&&x("percentage","Total weight must equal 100%")},[o.error]);const $=!e.new,D=n.filter(({id:C,weightType:A})=>C!==e.id&&A===Y.VARIABLE).length>0,P=C=>{const A=C.weightType===Y.VARIABLE,V=n.some(k=>k.weightType===Y.FIX),W=n.filter(k=>k.weightType===Y.VARIABLE).length===1;return V&&W&&A},B=C=>{w("name"),J(C,e.id)||x("name","A variant with that name already exists for this environment."),i(C)},I=C=>{(C===""||Q(C))&&g(C)},j=C=>{R(C)||x("payload","Invalid JSON.")},z=()=>{T.length>0&&v({type:"ADD",payload:{contextName:T[0].name,values:[]}})},L=C=>Boolean(C.length),J=(C,A)=>$||!n.some(V=>V.name===C&&V.id!==A),Q=C=>{if(!c)return!0;if(C===""||C.match(/\.[0-9]{2,}$/))return!1;const A=Number(C);return A>=0&&A<=100},R=C=>{try{return C.type==="json"&&JSON.parse(C.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:s,weight:Number(c?p:100)*10,weightType:c?Y.FIX:Y.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:y.map(C=>({contextName:C.contextName,values:C.values})).filter(C=>C.values&&C.values.length>0),isValid:L(s)&&J(s,e.id)&&Q(p)&&R(h)&&!o.error})},[s,c,p,h,y]),m.useEffect(()=>{c||g(String(e.weight/10))},[e.weight]),l(Cs,{children:[t(vs,{arrow:!0,title:P(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t($e,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>r(e.id),disabled:P(e),children:t(tt,{})})})}),l(Is,{children:[l(Es,{children:[t(Sn,{children:"Variant name"}),t(ws,{children:"This will be used to identify the variant in your code"}),t($t,{"data-testid":"VARIANT_NAME_INPUT",autoFocus:!0,label:"Variant name",error:Boolean(f.name),errorText:f.name,value:s,onChange:C=>B(C.target.value),disabled:$,required:!0})]}),t(E,{condition:D,show:l(xs,{children:[t(Ts,{label:"Custom percentage",control:t(ma,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:c,onChange:C=>u(C.target.checked)})}),t(As,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(f.percentage),errorText:f.percentage,value:p,onChange:C=>I(C.target.value),required:c,disabled:!c,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(fa,{position:"end",children:"%"})}})]})})]}),l(Pt,{children:["Payload",t(Ke,{tooltip:"Passed along with the the variant object."})]}),l(bn,{children:[t(Rs,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:ks,onChange:C=>{w("payload"),b(A=>({...A,type:C.target.value}))}}),t($t,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:C=>{w("payload"),b(A=>({...A,value:C.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>j(h),error:Boolean(f.payload),errorText:f.payload})]}),l(Pt,{children:["Overrides",t(Ke,{tooltip:"Here you can specify which users should get this variant."})]}),t(ys,{overrides:y,overridesDispatch:v}),t(Fs,{onClick:z,variant:"outlined",color:"primary",children:"Add override"})]})},Bs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-1.5),marginBottom:e.spacing(4)})),Os=d(Jt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Ds=d("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Vs=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ls=d(ge)(({theme:e})=>({marginBottom:e.spacing(2)})),Ms=d(ge)(({theme:e})=>({marginTop:e.spacing(4)})),_s=d("div")(({theme:e})=>({display:"flex",flexDirection:"column-reverse"})),js=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Bt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ns=d(Qt)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),zs=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Ws=d(re)(({theme:e})=>({marginLeft:e.spacing(3)})),Hs=({environment:e,open:n,setOpen:a,getApiPayload:r,getCrPayload:o,onConfirm:s})=>{var W;const i=F("projectId"),c=F("featureId"),{uiConfig:u}=ct(),{context:p}=lt(),{isChangeRequestConfigured:g}=ae(i),{data:h}=ve(i),{changeRequestInReviewOrApproved:b,alert:y}=Sa(h),v=(e==null?void 0:e.variants)||[],[T,f]=m.useState([]);m.useEffect(()=>{f(v.length?v.map(k=>({...k,isValid:!0,new:!1,id:je()})):[{name:"",weightType:Y.VARIABLE,weight:0,overrides:[],stickiness:(T==null?void 0:T.length)>0?T[0].stickiness:"default",new:!0,isValid:!1,id:je()}])},[n]);const S=(k,G)=>{f(H=>mt(H.map(xe=>xe.id===G?k:xe),1e3))},w=T.map(({new:k,isValid:G,id:H,...xe})=>xe),x=r(v,w),$=o(w),D=async k=>{k.preventDefault(),s(w)},P=()=>z?`curl --location --request POST '${u.unleashUrl}/api/admin/projects/${i}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
2
2
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
3
|
--header 'Content-Type: application/json' \\
|
|
4
4
|
--data-raw '${JSON.stringify($,void 0,2)}'`:`curl --location --request PATCH '${u.unleashUrl}/api/admin/projects/${i}/features/${c}/environments/${e==null?void 0:e.name}/variants' \\
|
|
@@ -6,4 +6,4 @@ import{az as vn,aA as wn,s as d,r as m,aB as Tn,aC as xn,aD as pt,j as t,aE as A
|
|
|
6
6
|
--header 'Content-Type: application/json' \\
|
|
7
7
|
--data-raw '${JSON.stringify(x.patch,void 0,2)}'`,B=T.every(({isValid:k})=>k),I=b((e==null?void 0:e.name)||""),j=I?"Add to existing change request":"Add change to draft",z=g((e==null?void 0:e.name)||"")&&u.flags.crOnVariants,L=((W=w[0])==null?void 0:W.stickiness)||"default",J=m.useMemo(()=>["default",...p.filter(k=>k.stickiness).map(k=>k.name)],[p]),Q=J.map(k=>({key:k,label:k}));J.includes(L)||Q.push({key:L,label:L});const R=async k=>{f(G=>G.map(H=>({...H,stickiness:k})))},C=k=>{R(k).catch(console.warn)},[A,V]=m.useState();return m.useEffect(()=>{V(void 0),x.error&&V(x.error)},[x.error]),t(Xe,{open:n,onClose:()=>{a(!1)},label:"",children:l(ya,{modal:!0,title:"",description:"Variants allows you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:P,loading:!n,children:[l(Bs,{children:[l("div",{children:[t(Os,{deprecated:!(e!=null&&e.enabled)}),t(Ds,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(oe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:()=>f(k=>[...k,{name:"",weightType:Y.VARIABLE,weight:0,overrides:[],stickiness:(k==null?void 0:k.length)>0?k[0].stickiness:"default",new:!0,isValid:!1,id:je()}]),variant:"outlined",permission:he,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),l(Vs,{onSubmit:D,children:[t(E,{condition:I,show:y,elseShow:t(E,{condition:Boolean(z),show:l(Ls,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(_s,{children:T.map(k=>t($s,{variant:k,variants:T,updateVariant:G=>S(G,k.id),removeVariant:()=>f(G=>mt(G.filter(H=>H.id!==k.id),1e3)),projectId:i,apiPayload:x},k.id))}),t(E,{condition:T.length>0,show:l(O,{children:[t(js,{children:t("p",{children:"Stickiness"})}),l(Bt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Ns,{options:Q,value:L,onChange:C})})]}),elseShow:t(Bt,{children:"This environment has no variants. Get started by adding a variant."})}),l(Ms,{severity:"error",hidden:!Boolean(A),children:[t("strong",{children:"Error: "}),A]}),l(zs,{children:[t(re,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!B,children:z?j:"Save variants"}),t(Ws,{onClick:()=>{a(!1)},children:"Cancel"})]})]})]})})},qs=d(M)(({theme:e})=>({fontSize:e.fontSizes.smallerBody,whiteSpace:"pre-wrap"})),Us=({value:e})=>{const{searchQuery:n}=Zt();return e?e.type==="string"&&e.value.length<20?t(te,{children:t(Je,{search:n,children:e.value})}):t(te,{children:t(en,{tooltip:t(O,{children:t(qs,{children:t(Je,{search:n,children:e.value})})}),highlighted:n.length>0&&e.value.toLowerCase().includes(n.toLowerCase()),children:e.type})}):t(te,{})},Gs=d(M)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Ys=({value:e})=>{const{searchQuery:n}=Zt();if(!e||e.length===0)return t(te,{});const a=r=>`${r.contextName}:${r.values.join()}`;return t(te,{children:t(en,{tooltip:t(O,{children:e.map((r,o)=>t(Gs,{children:t(Je,{search:n,children:a(r)})},r.contextName+o))}),highlighted:n.length>0&&(e==null?void 0:e.map(a).join(`
|
|
8
8
|
`).toLowerCase().includes(n.toLowerCase())),children:e.length===1?"1 override":`${e.length} overrides`})})},Ks=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),Xs=({environment:e,searchValue:n})=>{const a=F("projectId"),r=be(),o=ce(r.breakpoints.down("md")),s=ce(r.breakpoints.down("lg")),i=e.variants??[],c=m.useMemo(()=>[{Header:"Name",accessor:"name",Cell:ba,sortType:"alphanumeric",minWidth:350,searchable:!0},{Header:"Payload",accessor:"payload",Cell:Us,disableSortBy:!0,searchable:!0,filterParsing:S=>S==null?void 0:S.value},{Header:"Overrides",accessor:"overrides",Cell:Ys,disableSortBy:!0,searchable:!0,filterParsing:S=>(S==null?void 0:S.map(({contextName:w,values:x})=>`${w}:${x.join()}`).join(`
|
|
9
|
-
`))||""},{Header:"Weight",accessor:"weight",Cell:({row:{original:{name:S,weight:w}}})=>l(te,{"data-testid":`VARIANT_WEIGHT_${S}`,children:[Ca(w)," %"]}),sortType:"number"},{Header:"Type",accessor:S=>S.weightType==="fix"?"Fixed":"Variable",Cell:te,sortType:"alphanumeric"}],[a,i,e]),u=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{data:p,getSearchText:g}=va(c,n,i),{getTableProps:h,getTableBodyProps:b,headerGroups:y,rows:v,prepareRow:T,setHiddenColumns:f}=me.useTable({columns:c,data:p,initialState:u,sortTypes:wa,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},me.useSortBy);return tn([{condition:o,columns:["payload","overrides"]},{condition:s,columns:["weightType"]}],f,c),l(Ks,{children:[t(Ta,{value:g(n),children:l(nn,{...h(),children:[t(an,{headerGroups:y}),t(on,{...b(),children:v.map(S=>(T(S),t(rn,{hover:!0,...S.getRowProps(),children:S.cells.map(w=>t(sn,{...w.getCellProps(),children:w.render("Cell")}))})))})]})}),t(E,{condition:v.length===0,show:t(E,{condition:(n==null?void 0:n.length)>0,show:l(xa,{children:["No variants found matching “",n,"”"]})})})]})},Js=d("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.dividerAlternative}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Qs=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Zs=d(Jt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),ei=d("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),ti=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ni=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),ai=({environment:e,searchValue:n,children:a})=>{var s;const r=e.variants??[],o=((s=r[0])==null?void 0:s.stickiness)||"default";return l(Js,{children:[l(Qs,{children:[l("div",{children:[t(Zs,{deprecated:!e.enabled}),t(ei,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:r.length>0,show:l(O,{children:[t(Xs,{environment:e,searchValue:n}),t(E,{condition:r.length>1,show:l(O,{children:[l(ni,{children:[t("p",{children:"Stickiness:"}),t(Ye,{children:o})]}),l(ti,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},oi=d(at)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ri=({environment:e,permission:n,projectId:a,environmentId:r,onCopyVariantsFrom:o,otherEnvsWithVariants:s})=>{const[i,c]=m.useState(null),u=Boolean(i),p=e.variants??[];return t(E,{condition:s.length>0&&p.length===0,show:l(O,{children:[t(oe,{onClick:g=>{c(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":u?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:r,children:"Copy variants from"}),t(Be,{anchorEl:i,open:u,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:s.map(g=>t(Oe,{onClick:()=>o(g,e),children:t(oi,{children:`Copy from ${g.name}`})},g.name))})]})})},si=({permission:e,projectId:n,environment:a,checked:r,onClick:o,...s})=>{const i=Aa(e,n,a);return l(Oe,{disabled:!i,onClick:o,...s,children:[t(qt,{checked:r}),a]})},ii=d(Be)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),li=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),ci=d(re)(({theme:e})=>({marginTop:e.spacing(2)})),di=({current:e,environments:n,permission:a,projectId:r,onSubmit:o})=>{var T;const[s,i]=m.useState(null),c=Boolean(s),[u,p]=m.useState([]),g=f=>{p(S=>[...S,f])},h=f=>{p(S=>S.filter(({name:w})=>w!==f.name))},b=f=>{u.includes(f)?h(f):g(f)},y=()=>{p([]),i(null)},v=((T=n.find(f=>f.name===e))==null?void 0:T.variants)??[];return t(E,{condition:v.length>0&&n.length>1,show:l(O,{children:[t(re,{onClick:f=>{i(f.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Push to environment"}),l(ii,{anchorEl:s,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(f=>f.name!==e).map(f=>t(si,{projectId:r,permission:a,environment:f.name,checked:u.includes(f),onClick:()=>b(f)},f.name)),l(li,{children:[t(Re,{}),l(ci,{variant:"outlined",onClick:()=>{o(u),y()},disabled:u.length===0,children:["Push to selected (",u.length,")"]})]})]})]})})},ui=d(ge)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),pi=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),gi=()=>{const{uiConfig:e}=ct(),{setToastData:n,setToastApiError:a}=U(),r=be(),o=ce(r.breakpoints.down("md")),s=F("projectId"),i=F("featureId"),{feature:c,refetchFeature:u,loading:p}=_(s,i),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=Te(),{refetch:b}=ve(s),{addChange:y}=nt(),{isChangeRequestConfigured:v}=ae(s),[T,f]=m.useState(""),[S,w]=m.useState(),[x,$]=m.useState(!1),D=m.useMemo(()=>{var R;return((R=c==null?void 0:c.environments)==null?void 0:R.map(C=>({...C,crEnabled:e.flags.crOnVariants&&v(C.name)})))||[]},[c.environments,e.flags.crOnVariants]),P=(R,C)=>Ra(R,C),B=(R,C)=>{try{const A=Ia(C,1e3);return{patch:P(R,A)}}catch(A){return{patch:[],error:N(A)}}},I=R=>({feature:i,action:"patchVariant",payload:{variants:R}}),j=async(R,C)=>{if(R.crEnabled)await y(s,R.name,I(C)),b();else{const A=R.variants??[],{patch:V,error:W}=B(A,C);if(V.length===0)return;if(W){n({type:"error",title:W});return}await g(s,i,R.name,V)}u()},z=async(R,C)=>{try{const A=C.filter(({crEnabled:H})=>H),V=C.filter(({crEnabled:H})=>!H);A.length&&await Promise.all(A.map(H=>y(s,H.name,I(R)))),V.length&&await h(s,i,R,V.map(({name:H})=>H)),b(),u();const W=V.length?`Variants pushed to ${V.length===1?V[0].name:`${V.length} environments`}`:"",k=A.length?`Variants push added to ${A.length===1?`${A[0].name} draft`:`${A.length} drafts`}`:"",G=`${W}${W&&k?". ":""}${k}`;n({title:G,type:"success"})}catch(A){a(N(A))}},L=R=>{w(R),$(!0)},J=async R=>{if(S)try{await j(S,R),$(!1),n({title:S.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(C){a(N(C))}},Q=async(R,C)=>{try{const A=R.variants??[];await j(C,A),n({title:C.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(A){a(N(A))}};return l(dt,{isLoading:p,header:t(Ea,{title:"Variants",actions:t(E,{condition:!o,show:t(O,{children:t(ft,{initialValue:T,onChange:f})})}),children:t(E,{condition:o,show:t(ft,{initialValue:T,onChange:f})})}),children:[l(ui,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),D.map(R=>{var A;const C=D.filter(({name:V,variants:W})=>V!==R.name&&(W==null?void 0:W.length));return t(ai,{environment:R,searchValue:T,children:l(pi,{children:[t(di,{current:R.name,environments:D,permission:he,projectId:s,onSubmit:V=>z(R.variants??[],V)}),t(ri,{environment:R,permission:he,projectId:s,environmentId:R.name,onCopyVariantsFrom:Q,otherEnvsWithVariants:C}),t(E,{condition:Boolean((A=R.variants)==null?void 0:A.length),show:t(K,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>L(R),permission:he,projectId:s,environmentId:R.name,tooltipProps:{title:"Edit variants"},children:t(fe,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>L(R),variant:"outlined",permission:he,projectId:s,environmentId:R.name,children:"Add variant"})})]})},R.name)}),t(Hs,{environment:S,open:x,setOpen:$,getApiPayload:B,getCrPayload:I,onConfirm:J})]})},hi=ue("api/admin/client-metrics/features"),Cn=(e,n)=>{const a=ue(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:o}=et(a,()=>mi(a)),s=m.useCallback(()=>{Pe(hi).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!o&&!r,refetchFeatureMetrics:s,error:o}},mi=e=>fetch(e).then(Se("Features")).then(n=>n.json()).then(),ye=48,fi=({hoursBack:e,setHoursBack:n})=>{const a=r=>{n(yi(r))};return t(Qt,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:Si,value:String(e),onChange:a,fullWidth:!0})},yi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return ye}},Si=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${ye}`,label:`Last ${ye} hours`}],bi=({metrics:e,tableSectionId:n})=>{const a=ce(ln.breakpoints.down("md")),r=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:s,headerGroups:i,rows:c,prepareRow:u,setHiddenColumns:p}=me.useTable({initialState:r,columns:Ot,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:te}},me.useGlobalFilter,me.useSortBy);return tn([{condition:a,columns:["appName","environment"]}],p,Ot),e.length===0?null:l(nn,{...o(),rowHeight:"standard",id:n,children:[t(an,{headerGroups:i}),t(on,{...s(),children:c.map(g=>(u(g),t(rn,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(sn,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Ot=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Fa,{icon:t(go,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(ka,{value:e.row.original.timestamp})},{Header:"Application",accessor:"appName"},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ci=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((o,s)=>o+s.yes,0),[e]),r=m.useMemo(()=>e.reduce((o,s)=>o+s.no,0),[e]);return t(mn,{...n,totalYes:a,totalNo:r})},vi=({metrics:e,hoursBack:n})=>{const a=yt(),r=yt();return e.length===0?l(q,{mt:6,children:[t(M,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(M,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):l(m.Suspense,{fallback:null,children:[t(q,{borderTop:1,pt:2,mt:3,borderColor:ln.palette.grey[200],children:t(wi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(q,{mt:4,children:t(Ci,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:r})}),t(q,{mt:4,children:t(bi,{metrics:e,tableSectionId:r})})]})},wi=Pa.lazy(()=>import("./FeatureMetricsChart-86cc2280.js")),Ze=e=>{const{search:n}=window.location,a=pe(),r=m.useMemo(()=>new URLSearchParams(n),[n]),o=m.useCallback(s=>{const i=new URLSearchParams(n);i.set(e,s),a({search:i.toString()},{replace:!0})},[e,n,a]);return[r.get(e)||void 0,o]},Ti=e=>{const[n,a]=Ze(e),r=m.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,r]},xi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ai=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Ei=d("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText}})),Dt=({title:e,values:n,value:a,setValue:r})=>{const o=i=>()=>{n.has(i)&&r(i)},s=m.useMemo(()=>Array.from(n).sort((i,c)=>i.localeCompare(c)),[n]);return l("div",{children:[t(xi,{children:e}),t(Ai,{children:s.map(i=>t(Ei,{children:t(De,{label:i,onClick:o(i),"aria-pressed":i===a,sx:$a})},i))})]})},Ii=d("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),Ri=()=>{const e=F("projectId"),n=F("featureId"),a=Fi(e,n),r=ki(n);Gt("Metrics");const[o=ye,s]=Ti("hoursBack"),{featureMetrics:i}=Cn(n,o),[c,u]=m.useState(i);m.useEffect(()=>{i&&u(i)},[i]);const p=Array.from(a)[0],g=Array.from(r)[0],[h=p,b]=Ze("environment"),[y=g,v]=Ze("application"),T=m.useMemo(()=>c==null?void 0:c.filter(f=>f.environment===h).filter(f=>f.appName===y),[c,h,y]);return T?l(dt,{children:[l(ee,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(Dt,{title:"Environments",values:a,value:h,setValue:b})})}),t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:r.size>0,show:t(Dt,{title:"Applications",values:r,value:y,setValue:v})})}),t(ee,{item:!0,xs:12,md:2,children:t(Ii,{children:t(fi,{hoursBack:o,setHoursBack:s})})})]}),t(vi,{metrics:T,hoursBack:o})]}):null},Fi=(e,n)=>{const{feature:a}=_(e,n),r=a.environments.map(o=>o.name);return new Set(r)},ki=e=>{const{featureMetrics:n=[]}=Cn(e,ye),a=n.map(r=>r.appName);return new Set(a)},Pi=(e,n)=>{const a=new Set(e),r=new Set(n);return a.size!==r.size?!1:[...a].every(o=>r.has(o))},Vt=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Lt=d(ge)(({theme:e})=>({marginBottom:e.spacing(1)})),$i=d(st)({padding:0}),Bi=({projectId:e,open:n,onClose:a,onClick:r,feature:o,changeRequests:s})=>{const i=F("projectId"),{project:c}=cn(e),u=m.useMemo(()=>Pi(o.environments.map(g=>g.name),c.environments),[o,c]),p=s?s.length>0:!1;return t(E,{condition:u&&!p,show:t(ie,{open:n,onClose:a,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:l(Vt,{children:[t(Lt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ie,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"OK",children:l(Vt,{children:[t(Lt,{severity:"warning",children:"Incompatible project environments"}),t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."}),t(E,{condition:p,show:l(O,{children:[t("p",{children:"In addition the feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t($i,{children:s==null?void 0:s.map(g=>t(Ie,{children:l(X,{to:`/projects/${i}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})})]})})})},Oi=e=>fetch(e).then(Se("ChangeRequest")).then(n=>n.json()),Di=(e,n)=>{const{data:a,error:r,mutate:o}=Ba([],ue(`api/admin/projects/${e}/change-requests/pending/${n}`),Oi);return{changeRequests:a,loading:!r&&!a,refetch:o,error:r}},Vi=()=>{const{hasAccess:e}=m.useContext(ot),n=F("projectId"),a=F("featureId"),{feature:r,refetchFeature:o}=_(n,a),[s,i]=m.useState(!1),{changeFeatureProject:c}=Te(),{setToastData:u,setToastApiError:p}=U(),[g,h]=m.useState(n),{projects:b}=Oa(),y=pe(),{changeRequests:v}=Di(n,a),T=async()=>{try{g&&(await c(n,a,g),o(),u({title:"Project changed",type:"success"}),i(!1),y(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(S){p(N(S))}},f=m.useMemo(()=>b.map(S=>S.id).filter(S=>e(St,S)),[b,e]);return f.length===0?null:l(O,{children:[t(Da,{value:g,onChange:h,label:"Project",filter:S=>f.includes(S),enabled:!0}),t(oe,{permission:St,onClick:()=>i(!0),disabled:g===n,projectId:n,children:"Save"}),t(Bi,{changeRequests:v,projectId:g,open:s,feature:r,onClose:()=>i(!1),onClick:T})]})},Li=d("div")({display:"flex",alignItems:"center"}),Mi=d(M)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),_i=({projectId:e,featureId:n})=>{var s;const{feature:a}=_(e,n),r=pe();return l(O,{children:[l(Li,{children:[t(Mi,{children:"Feature information"}),t(K,{permission:se,projectId:e,"data-loading":!0,onClick:()=>{r(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(fe,{})})]}),l(M,{children:["Name: ",t("strong",{children:a.name})]}),l(M,{children:["Description:"," ",t("strong",{children:(s=a.description)!=null&&s.length?a.description:"no description"})]}),l(M,{children:["Type: ",t("strong",{children:a.type})]}),l(M,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Ae="metadata",Ge="project",ji=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Ni=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),zi=()=>{const e=F("projectId"),n=F("featureId"),[a,r]=m.useState(Ae),{uiConfig:o}=ct();return t(dt,{header:"Settings",sx:{padding:0},children:l(q,{sx:{display:"flex"},children:[t(ji,{children:l(st,{children:[t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Ae),selected:a===Ae,children:"Metadata"},0),t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Ge),selected:a===Ge,hidden:!o.flags.P,children:"Project"},1)]})}),l(Ni,{children:[t(E,{condition:a===Ae,show:t(_i,{projectId:e,featureId:n})}),t(E,{condition:a===Ge&&o.flags.P,show:t(Vi,{})})]})]})})},Wi=d(De)(({theme:e})=>({background:"transparent",border:`1px solid ${e.palette.primary.main}`,color:e.palette.primary.main})),Hi=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Wi,{color:"primary",variant:"outlined",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",label:e?"Stale":"Active"})}),Mt=d("strong")({wordBreak:"break-all"}),qi=()=>{const e=F("projectId"),n=F("featureId"),{archivedFeatures:a}=Va(),r=La(e,{name:n});return a?a.some(s=>s.name===n)?l("p",{children:["The feature ",t(Mt,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):l("p",{children:["The feature ",t(Mt,{children:n})," does not exist. Would you like to"," ",t(X,{to:r,children:"create it"}),"?"]}):null},Ui=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Gi=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Yi=d("div")({display:"flex",alignItems:"center"}),Ki=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Xi=d("div")({flexShrink:0,display:"flex"}),Ji=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.tertiary.light,height:"1px"})),Qi=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Zi=d(Ma)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),rl=()=>{const e=F("projectId"),n=F("featureId"),{refetch:a}=cn(e),{favorite:r,unfavorite:o}=_a(),{refetchFeature:s}=_(e,n),[i,c]=m.useState(!1),[u,p]=m.useState(!1),[g,h]=m.useState(!1),b=ce(`(max-width:${500}px)`),{feature:y,loading:v,error:T,status:f}=_(e,n),S=pe(),{pathname:w}=ja(),x=Na(v),$=`/projects/${e}/features/${n}`,D=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],P=D.find(I=>I.path===w)??D[0],B=async()=>{y!=null&&y.favorite?await o(e,y.name):await r(e,y.name),s()};return f===404?t(qi,{}):T!==void 0?t("div",{ref:x}):l("div",{ref:x,children:[l(Ui,{children:[l(Gi,{children:[l(Yi,{children:[t(za,{onClick:B,isFavorite:y==null?void 0:y.favorite}),l(Ki,{"data-loading":!0,children:[y.name," "]}),t(E,{condition:!b,show:t(Hi,{stale:y==null?void 0:y.stale})})]}),l(Xi,{children:[t(K,{permission:Wa,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Ha,{})}),t(K,{permission:qa,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(po,{})}),t(K,{onClick:()=>h(!0),permission:se,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(mo,{})}),t(K,{onClick:()=>c(!0),permission:se,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Ua,{})})]})]}),t(Ji,{}),t(Qi,{children:t(Ga,{value:P.path,indicatorColor:"primary",textColor:"primary",children:D.map(I=>t(Zi,{label:I.title,value:I.path,onClick:()=>S(I.path)},I.title))})})]}),l(Yt,{children:[t(ne,{path:"metrics",element:t(Ri,{})}),t(ne,{path:"logs",element:t(yo,{})}),t(ne,{path:"variants",element:t(gi,{})}),t(ne,{path:"settings",element:t(zi,{})}),t(ne,{path:"*",element:t(ds,{})})]}),t(to,{isOpen:u,onConfirm:()=>{a(),S(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureId:n}),t(no,{isStale:y.stale,isOpen:g,onClose:()=>{h(!1),s()},featureId:n,projectId:e}),t(yn,{open:i,setOpen:c})]})};export{rl as default};
|
|
9
|
+
`))||""},{Header:"Weight",accessor:"weight",Cell:({row:{original:{name:S,weight:w}}})=>l(te,{"data-testid":`VARIANT_WEIGHT_${S}`,children:[Ca(w)," %"]}),sortType:"number"},{Header:"Type",accessor:S=>S.weightType==="fix"?"Fixed":"Variable",Cell:te,sortType:"alphanumeric"}],[a,i,e]),u=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{data:p,getSearchText:g}=va(c,n,i),{getTableProps:h,getTableBodyProps:b,headerGroups:y,rows:v,prepareRow:T,setHiddenColumns:f}=me.useTable({columns:c,data:p,initialState:u,sortTypes:wa,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},me.useSortBy);return tn([{condition:o,columns:["payload","overrides"]},{condition:s,columns:["weightType"]}],f,c),l(Ks,{children:[t(Ta,{value:g(n),children:l(nn,{...h(),children:[t(an,{headerGroups:y}),t(on,{...b(),children:v.map(S=>(T(S),t(rn,{hover:!0,...S.getRowProps(),children:S.cells.map(w=>t(sn,{...w.getCellProps(),children:w.render("Cell")}))})))})]})}),t(E,{condition:v.length===0,show:t(E,{condition:(n==null?void 0:n.length)>0,show:l(xa,{children:["No variants found matching “",n,"”"]})})})]})},Js=d("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.dividerAlternative}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Qs=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Zs=d(Jt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),ei=d("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),ti=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ni=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),ai=({environment:e,searchValue:n,children:a})=>{var s;const r=e.variants??[],o=((s=r[0])==null?void 0:s.stickiness)||"default";return l(Js,{children:[l(Qs,{children:[l("div",{children:[t(Zs,{deprecated:!e.enabled}),t(ei,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:r.length>0,show:l(O,{children:[t(Xs,{environment:e,searchValue:n}),t(E,{condition:r.length>1,show:l(O,{children:[l(ni,{children:[t("p",{children:"Stickiness:"}),t(Ye,{children:o})]}),l(ti,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},oi=d(at)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ri=({environment:e,permission:n,projectId:a,environmentId:r,onCopyVariantsFrom:o,otherEnvsWithVariants:s})=>{const[i,c]=m.useState(null),u=Boolean(i),p=e.variants??[];return t(E,{condition:s.length>0&&p.length===0,show:l(O,{children:[t(oe,{onClick:g=>{c(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":u?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:r,children:"Copy variants from"}),t(Be,{anchorEl:i,open:u,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:s.map(g=>t(Oe,{onClick:()=>o(g,e),children:t(oi,{children:`Copy from ${g.name}`})},g.name))})]})})},si=({permission:e,projectId:n,environment:a,checked:r,onClick:o,...s})=>{const i=Aa(e,n,a);return l(Oe,{disabled:!i,onClick:o,...s,children:[t(qt,{checked:r}),a]})},ii=d(Be)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),li=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),ci=d(re)(({theme:e})=>({marginTop:e.spacing(2)})),di=({current:e,environments:n,permission:a,projectId:r,onSubmit:o})=>{var T;const[s,i]=m.useState(null),c=Boolean(s),[u,p]=m.useState([]),g=f=>{p(S=>[...S,f])},h=f=>{p(S=>S.filter(({name:w})=>w!==f.name))},b=f=>{u.includes(f)?h(f):g(f)},y=()=>{p([]),i(null)},v=((T=n.find(f=>f.name===e))==null?void 0:T.variants)??[];return t(E,{condition:v.length>0&&n.length>1,show:l(O,{children:[t(re,{onClick:f=>{i(f.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Push to environment"}),l(ii,{anchorEl:s,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(f=>f.name!==e).map(f=>t(si,{projectId:r,permission:a,environment:f.name,checked:u.includes(f),onClick:()=>b(f)},f.name)),l(li,{children:[t(Re,{}),l(ci,{variant:"outlined",onClick:()=>{o(u),y()},disabled:u.length===0,children:["Push to selected (",u.length,")"]})]})]})]})})},ui=d(ge)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),pi=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),gi=()=>{const{uiConfig:e}=ct(),{setToastData:n,setToastApiError:a}=U(),r=be(),o=ce(r.breakpoints.down("md")),s=F("projectId"),i=F("featureId"),{feature:c,refetchFeature:u,loading:p}=_(s,i),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=Te(),{refetch:b}=ve(s),{addChange:y}=nt(),{isChangeRequestConfigured:v}=ae(s),[T,f]=m.useState(""),[S,w]=m.useState(),[x,$]=m.useState(!1),D=m.useMemo(()=>{var R;return((R=c==null?void 0:c.environments)==null?void 0:R.map(C=>({...C,crEnabled:e.flags.crOnVariants&&v(C.name)})))||[]},[c.environments,e.flags.crOnVariants]),P=(R,C)=>Ra(R,C),B=(R,C)=>{try{const A=Ia(C,1e3);return{patch:P(R,A)}}catch(A){return{patch:[],error:N(A)}}},I=R=>({feature:i,action:"patchVariant",payload:{variants:R}}),j=async(R,C)=>{if(R.crEnabled)await y(s,R.name,I(C)),b();else{const A=R.variants??[],{patch:V,error:W}=B(A,C);if(V.length===0)return;if(W){n({type:"error",title:W});return}await g(s,i,R.name,V)}u()},z=async(R,C)=>{try{const A=C.filter(({crEnabled:H})=>H),V=C.filter(({crEnabled:H})=>!H);A.length&&await Promise.all(A.map(H=>y(s,H.name,I(R)))),V.length&&await h(s,i,R,V.map(({name:H})=>H)),b(),u();const W=V.length?`Variants pushed to ${V.length===1?V[0].name:`${V.length} environments`}`:"",k=A.length?`Variants push added to ${A.length===1?`${A[0].name} draft`:`${A.length} drafts`}`:"",G=`${W}${W&&k?". ":""}${k}`;n({title:G,type:"success"})}catch(A){a(N(A))}},L=R=>{w(R),$(!0)},J=async R=>{if(S)try{await j(S,R),$(!1),n({title:S.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(C){a(N(C))}},Q=async(R,C)=>{try{const A=R.variants??[];await j(C,A),n({title:C.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(A){a(N(A))}};return l(dt,{isLoading:p,header:t(Ea,{title:"Variants",actions:t(E,{condition:!o,show:t(O,{children:t(ft,{initialValue:T,onChange:f})})}),children:t(E,{condition:o,show:t(ft,{initialValue:T,onChange:f})})}),children:[l(ui,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),D.map(R=>{var A;const C=D.filter(({name:V,variants:W})=>V!==R.name&&(W==null?void 0:W.length));return t(ai,{environment:R,searchValue:T,children:l(pi,{children:[t(di,{current:R.name,environments:D,permission:he,projectId:s,onSubmit:V=>z(R.variants??[],V)}),t(ri,{environment:R,permission:he,projectId:s,environmentId:R.name,onCopyVariantsFrom:Q,otherEnvsWithVariants:C}),t(E,{condition:Boolean((A=R.variants)==null?void 0:A.length),show:t(K,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>L(R),permission:he,projectId:s,environmentId:R.name,tooltipProps:{title:"Edit variants"},children:t(fe,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>L(R),variant:"outlined",permission:he,projectId:s,environmentId:R.name,children:"Add variant"})})]})},R.name)}),t(Hs,{environment:S,open:x,setOpen:$,getApiPayload:B,getCrPayload:I,onConfirm:J})]})},hi=ue("api/admin/client-metrics/features"),Cn=(e,n)=>{const a=ue(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:o}=et(a,()=>mi(a)),s=m.useCallback(()=>{Pe(hi).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!o&&!r,refetchFeatureMetrics:s,error:o}},mi=e=>fetch(e).then(Se("Features")).then(n=>n.json()).then(),ye=48,fi=({hoursBack:e,setHoursBack:n})=>{const a=r=>{n(yi(r))};return t(Qt,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:Si,value:String(e),onChange:a,fullWidth:!0})},yi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return ye}},Si=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${ye}`,label:`Last ${ye} hours`}],bi=({metrics:e,tableSectionId:n})=>{const a=ce(ln.breakpoints.down("md")),r=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:s,headerGroups:i,rows:c,prepareRow:u,setHiddenColumns:p}=me.useTable({initialState:r,columns:Ot,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:te}},me.useGlobalFilter,me.useSortBy);return tn([{condition:a,columns:["appName","environment"]}],p,Ot),e.length===0?null:l(nn,{...o(),rowHeight:"standard",id:n,children:[t(an,{headerGroups:i}),t(on,{...s(),children:c.map(g=>(u(g),t(rn,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(sn,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Ot=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Fa,{icon:t(go,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(ka,{value:e.row.original.timestamp})},{Header:"Application",accessor:"appName"},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ci=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((o,s)=>o+s.yes,0),[e]),r=m.useMemo(()=>e.reduce((o,s)=>o+s.no,0),[e]);return t(mn,{...n,totalYes:a,totalNo:r})},vi=({metrics:e,hoursBack:n})=>{const a=yt(),r=yt();return e.length===0?l(q,{mt:6,children:[t(M,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(M,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):l(m.Suspense,{fallback:null,children:[t(q,{borderTop:1,pt:2,mt:3,borderColor:ln.palette.grey[200],children:t(wi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(q,{mt:4,children:t(Ci,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:r})}),t(q,{mt:4,children:t(bi,{metrics:e,tableSectionId:r})})]})},wi=Pa.lazy(()=>import("./FeatureMetricsChart-1e05efb3.js")),Ze=e=>{const{search:n}=window.location,a=pe(),r=m.useMemo(()=>new URLSearchParams(n),[n]),o=m.useCallback(s=>{const i=new URLSearchParams(n);i.set(e,s),a({search:i.toString()},{replace:!0})},[e,n,a]);return[r.get(e)||void 0,o]},Ti=e=>{const[n,a]=Ze(e),r=m.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,r]},xi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ai=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Ei=d("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText}})),Dt=({title:e,values:n,value:a,setValue:r})=>{const o=i=>()=>{n.has(i)&&r(i)},s=m.useMemo(()=>Array.from(n).sort((i,c)=>i.localeCompare(c)),[n]);return l("div",{children:[t(xi,{children:e}),t(Ai,{children:s.map(i=>t(Ei,{children:t(De,{label:i,onClick:o(i),"aria-pressed":i===a,sx:$a})},i))})]})},Ii=d("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),Ri=()=>{const e=F("projectId"),n=F("featureId"),a=Fi(e,n),r=ki(n);Gt("Metrics");const[o=ye,s]=Ti("hoursBack"),{featureMetrics:i}=Cn(n,o),[c,u]=m.useState(i);m.useEffect(()=>{i&&u(i)},[i]);const p=Array.from(a)[0],g=Array.from(r)[0],[h=p,b]=Ze("environment"),[y=g,v]=Ze("application"),T=m.useMemo(()=>c==null?void 0:c.filter(f=>f.environment===h).filter(f=>f.appName===y),[c,h,y]);return T?l(dt,{children:[l(ee,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(Dt,{title:"Environments",values:a,value:h,setValue:b})})}),t(ee,{item:!0,xs:12,md:5,children:t(E,{condition:r.size>0,show:t(Dt,{title:"Applications",values:r,value:y,setValue:v})})}),t(ee,{item:!0,xs:12,md:2,children:t(Ii,{children:t(fi,{hoursBack:o,setHoursBack:s})})})]}),t(vi,{metrics:T,hoursBack:o})]}):null},Fi=(e,n)=>{const{feature:a}=_(e,n),r=a.environments.map(o=>o.name);return new Set(r)},ki=e=>{const{featureMetrics:n=[]}=Cn(e,ye),a=n.map(r=>r.appName);return new Set(a)},Pi=(e,n)=>{const a=new Set(e),r=new Set(n);return a.size!==r.size?!1:[...a].every(o=>r.has(o))},Vt=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Lt=d(ge)(({theme:e})=>({marginBottom:e.spacing(1)})),$i=d(st)({padding:0}),Bi=({projectId:e,open:n,onClose:a,onClick:r,feature:o,changeRequests:s})=>{const i=F("projectId"),{project:c}=cn(e),u=m.useMemo(()=>Pi(o.environments.map(g=>g.name),c.environments),[o,c]),p=s?s.length>0:!1;return t(E,{condition:u&&!p,show:t(ie,{open:n,onClose:a,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:l(Vt,{children:[t(Lt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ie,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"OK",children:l(Vt,{children:[t(Lt,{severity:"warning",children:"Incompatible project environments"}),t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."}),t(E,{condition:p,show:l(O,{children:[t("p",{children:"In addition the feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t($i,{children:s==null?void 0:s.map(g=>t(Ie,{children:l(X,{to:`/projects/${i}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})})]})})})},Oi=e=>fetch(e).then(Se("ChangeRequest")).then(n=>n.json()),Di=(e,n)=>{const{data:a,error:r,mutate:o}=Ba([],ue(`api/admin/projects/${e}/change-requests/pending/${n}`),Oi);return{changeRequests:a,loading:!r&&!a,refetch:o,error:r}},Vi=()=>{const{hasAccess:e}=m.useContext(ot),n=F("projectId"),a=F("featureId"),{feature:r,refetchFeature:o}=_(n,a),[s,i]=m.useState(!1),{changeFeatureProject:c}=Te(),{setToastData:u,setToastApiError:p}=U(),[g,h]=m.useState(n),{projects:b}=Oa(),y=pe(),{changeRequests:v}=Di(n,a),T=async()=>{try{g&&(await c(n,a,g),o(),u({title:"Project changed",type:"success"}),i(!1),y(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(S){p(N(S))}},f=m.useMemo(()=>b.map(S=>S.id).filter(S=>e(St,S)),[b,e]);return f.length===0?null:l(O,{children:[t(Da,{value:g,onChange:h,label:"Project",filter:S=>f.includes(S),enabled:!0}),t(oe,{permission:St,onClick:()=>i(!0),disabled:g===n,projectId:n,children:"Save"}),t(Bi,{changeRequests:v,projectId:g,open:s,feature:r,onClose:()=>i(!1),onClick:T})]})},Li=d("div")({display:"flex",alignItems:"center"}),Mi=d(M)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),_i=({projectId:e,featureId:n})=>{var s;const{feature:a}=_(e,n),r=pe();return l(O,{children:[l(Li,{children:[t(Mi,{children:"Feature information"}),t(K,{permission:se,projectId:e,"data-loading":!0,onClick:()=>{r(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(fe,{})})]}),l(M,{children:["Name: ",t("strong",{children:a.name})]}),l(M,{children:["Description:"," ",t("strong",{children:(s=a.description)!=null&&s.length?a.description:"no description"})]}),l(M,{children:["Type: ",t("strong",{children:a.type})]}),l(M,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Ae="metadata",Ge="project",ji=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Ni=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),zi=()=>{const e=F("projectId"),n=F("featureId"),[a,r]=m.useState(Ae),{uiConfig:o}=ct();return t(dt,{header:"Settings",sx:{padding:0},children:l(q,{sx:{display:"flex"},children:[t(ji,{children:l(st,{children:[t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Ae),selected:a===Ae,children:"Metadata"},0),t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Ge),selected:a===Ge,hidden:!o.flags.P,children:"Project"},1)]})}),l(Ni,{children:[t(E,{condition:a===Ae,show:t(_i,{projectId:e,featureId:n})}),t(E,{condition:a===Ge&&o.flags.P,show:t(Vi,{})})]})]})})},Wi=d(De)(({theme:e})=>({background:"transparent",border:`1px solid ${e.palette.primary.main}`,color:e.palette.primary.main})),Hi=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Wi,{color:"primary",variant:"outlined",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",label:e?"Stale":"Active"})}),Mt=d("strong")({wordBreak:"break-all"}),qi=()=>{const e=F("projectId"),n=F("featureId"),{archivedFeatures:a}=Va(),r=La(e,{name:n});return a?a.some(s=>s.name===n)?l("p",{children:["The feature ",t(Mt,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):l("p",{children:["The feature ",t(Mt,{children:n})," does not exist. Would you like to"," ",t(X,{to:r,children:"create it"}),"?"]}):null},Ui=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Gi=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Yi=d("div")({display:"flex",alignItems:"center"}),Ki=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Xi=d("div")({flexShrink:0,display:"flex"}),Ji=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.tertiary.light,height:"1px"})),Qi=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Zi=d(Ma)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),rl=()=>{const e=F("projectId"),n=F("featureId"),{refetch:a}=cn(e),{favorite:r,unfavorite:o}=_a(),{refetchFeature:s}=_(e,n),[i,c]=m.useState(!1),[u,p]=m.useState(!1),[g,h]=m.useState(!1),b=ce(`(max-width:${500}px)`),{feature:y,loading:v,error:T,status:f}=_(e,n),S=pe(),{pathname:w}=ja(),x=Na(v),$=`/projects/${e}/features/${n}`,D=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],P=D.find(I=>I.path===w)??D[0],B=async()=>{y!=null&&y.favorite?await o(e,y.name):await r(e,y.name),s()};return f===404?t(qi,{}):T!==void 0?t("div",{ref:x}):l("div",{ref:x,children:[l(Ui,{children:[l(Gi,{children:[l(Yi,{children:[t(za,{onClick:B,isFavorite:y==null?void 0:y.favorite}),l(Ki,{"data-loading":!0,children:[y.name," "]}),t(E,{condition:!b,show:t(Hi,{stale:y==null?void 0:y.stale})})]}),l(Xi,{children:[t(K,{permission:Wa,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Ha,{})}),t(K,{permission:qa,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(po,{})}),t(K,{onClick:()=>h(!0),permission:se,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(mo,{})}),t(K,{onClick:()=>c(!0),permission:se,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Ua,{})})]})]}),t(Ji,{}),t(Qi,{children:t(Ga,{value:P.path,indicatorColor:"primary",textColor:"primary",children:D.map(I=>t(Zi,{label:I.title,value:I.path,onClick:()=>S(I.path)},I.title))})})]}),l(Yt,{children:[t(ne,{path:"metrics",element:t(Ri,{})}),t(ne,{path:"logs",element:t(yo,{})}),t(ne,{path:"variants",element:t(gi,{})}),t(ne,{path:"settings",element:t(zi,{})}),t(ne,{path:"*",element:t(ds,{})})]}),t(to,{isOpen:u,onConfirm:()=>{a(),S(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureId:n}),t(no,{isStale:y.stale,isOpen:g,onClose:()=>{h(!1),s()},featureId:n,projectId:e}),t(yn,{open:i,setOpen:c})]})};export{rl as default};
|