unleash-server 4.20.4 → 4.20.5-beta.0
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-29a2b285.js → CreateProject-f3e27e64.js} +1 -1
- package/frontend/build/static/{Error-934cc570.js → Error-3a9a6e2a.js} +1 -1
- package/frontend/build/static/{ExpandMore-c3e13d73.js → ExpandMore-46f830cb.js} +1 -1
- package/frontend/build/static/{FeatureArchiveDialog-b5fc8177.js → FeatureArchiveDialog-57c6d9ed.js} +2 -2
- package/frontend/build/static/{FeatureMetricsChart-13ce1b57.js → FeatureMetricsChart-d491608e.js} +1 -1
- package/frontend/build/static/FeatureViewLazyExport-b0689708.js +9 -0
- package/frontend/build/static/{LazyAdminExport-2f5a25ac.js → LazyAdminExport-62d63b43.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-dc65603b.js → LazyProjectExport-7200e7dc.js} +1 -1
- package/frontend/build/static/{NetworkOverview-8018cd89.js → NetworkOverview-42db0a7a.js} +75 -75
- package/frontend/build/static/{NetworkTraffic-84935c51.js → NetworkTraffic-7c9567ee.js} +1 -1
- package/frontend/build/static/{Playground-6d2eacce.js → Playground-13a05a33.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-93cba46f.js → StrategyItemContainer-66556bf6.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-38d041f7.js → chartjs-adapter-date-fns.esm-4b4ea41a.js} +1 -1
- package/frontend/build/static/{index-c290f941.js → index-54a8dd7a.js} +73 -73
- package/frontend/build/static/{index-3132dba8.js → index-a4c3dd25.js} +1 -1
- package/frontend/build/static/{index-66dec49c.js → index-b275e721.js} +1 -1
- package/frontend/build/static/{unknownify-86fd295b.js → unknownify-8b8ea1ba.js} +1 -1
- package/frontend/build/static/{useProjectRole-b5b140d2.js → useProjectRole-f229b4e4.js} +1 -1
- package/frontend/build/static/v4-a960c1f4.js +1 -0
- package/frontend/package.json +1 -0
- package/package.json +1 -1
- package/frontend/build/static/FeatureViewLazyExport-1bee3351.js +0 -9
|
@@ -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-54a8dd7a.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-54a8dd7a.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-54a8dd7a.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-54a8dd7a.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-b5fc8177.js → FeatureArchiveDialog-57c6d9ed.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aE as A,b6 as F,f as p,aP as C,j as o,C as E,A as K,T,
|
|
1
|
+
import{aE as A,b6 as F,f as p,aP as C,j as o,C as E,A as K,T,ca as J,cy as x,r as d,cz as Q,cA as X,b4 as Z,b5 as B,a2 as S,H as ee,ar as P,aF as D,a$ as te,cB as ae,au as ne,ap as se,cC as re,cD as oe,cE as ie,cF as ce,bd as $,cG as ue,b7 as le,a4 as v,cH as ge,s as j,b3 as de,cI as he,cJ as ye,F as fe,aM as N}from"./index-54a8dd7a.js";const Re=({isOpen:e,onConfirm:t,onClose:a,showBanner:n,environment:s,messageComponent:r})=>{const i=A("projectId"),{data:l}=F(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(E,{condition:c,show:g}),o(E,{condition:Boolean(n),show:p(K,{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(T,{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}=B(),{setToastData:b,setToastApiError:O}=S(),{uiConfig:Y}=ee(),{unleashUrl:z}=Y,L=P(),{feature:y,refetchFeature:w}=D(e,t),q=d.useRef(y),{isChangeRequestConfigured:k}=te(e),{refetch:_}=F(e),{data:R,staleDataNotification:U,forceRefreshCache:W}=ae({unleashGetter:D,params:[e,t],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},y,{afterSubmitAction:w},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),b({title:"Strategy created",type:"success",confetti:!0})},H=async f=>{await m(e,a,{action:"addStrategy",feature:t,payload:f}),b({title:"Strategy added to draft",type:"success",confetti:!0}),_()},M=async()=>{const f=ue(s,i);try{k(a)?await H(f):await G(f),w(),L(le(e,t))}catch(V){O(v(V))}};return!R||!R.project?null:p(ne,{modal:!0,title:se(n),description:re,documentationLink:oe,documentationLinkLabel:ie,formatApiCode:()=>Te(e,t,a,s,z),children:[o(ce,{projectId:e,feature:R,strategy:s,setStrategy:r,segments:i,setSegments:l,environmentId:a,onSubmit:M,loading:h,permission:$,errors:g,isChangeRequest:k(a)}),U]})},be=(e,t,a,n)=>{const s=new URLSearchParams({environmentId:a,strategyName:n});return`/projects/${e}/features/${t}/strategies/create?${s}`},Te=(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
|
-
--data-raw '${i}'`},
|
|
4
|
+
--data-raw '${i}'`},I=j("p")(({theme:e})=>({marginBottom:e.spacing(.5),fontSize:e.fontSizes.bodySize})),Ee=({open:e,environmentName:t,featureId:a,projectId:n,onClose:s})=>{const r=P(),i=be(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(I,{children:"Before you can enable the toggle in the environment, you need to add an activation strategy."}),o(I,{children:"You can add the activation strategy by selecting the toggle, open the environment accordion and add the activation strategy."})]})},Fe="You can not enable the environment before it has strategies",we=e=>{const{setToastData:t,setToastApiError:a}=S(),{addChange:n}=B(),{refetch:s}=F(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(T,{"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",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(T,{children:"Setting a toggle to stale marks it for cleanup"}),g=o(T,{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(b){i(v(b))}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(E,{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,Fe as E,Ae as F,qe as U,ke as V,Ee as a,De as b,xe as c,be as f,we as u};
|
package/frontend/build/static/{FeatureMetricsChart-13ce1b57.js → FeatureMetricsChart-d491608e.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c0 as i,
|
|
1
|
+
import{c0 as i,eV as p,bF as y,r as l,j as u}from"./index-54a8dd7a.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-4b4ea41a.js";import"./index-b275e721.js";import"./index-a4c3dd25.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};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{az as aa,aA as ra,s as p,r as m,aB as oa,_ as sa,$ as Vt,j as t,aC as ia,aD as la,c as qe,aE as k,aF as _,aG as ca,aH as da,aI as bt,aJ as Pe,aK as Ge,w as Be,ai as ua,aL as cn,aM as ce,a2 as K,aN as $e,aO as fe,f as c,aP as ie,C as E,a4 as j,aQ as dn,aR as at,aS as pa,aT as ga,aU as ha,H as Te,aV as ma,aW as ne,aX as se,aY as Se,aZ as ya,a_ as vt,u as Ye,a$ as pe,F as O,b0 as Dt,b1 as Ot,b2 as Ve,b3 as ge,T as H,b4 as De,ar as xe,b5 as Ct,b6 as Oe,A as he,b7 as un,b8 as fa,b9 as Sa,ba,bb as va,ap as Le,bc as Ca,bd as be,be as le,m as Ne,bf as wa,bg as Ta,bh as Ke,a8 as Je,bi as pn,bj as gn,bk as wt,bl as xa,bm as Aa,bn as Ea,a as Q,p as Ia,N as ue,B as gt,a9 as me,bo as Ra,x as Xe,an as _e,E as ka,bp as Tt,bq as ze,P as Fa,br as Pa,bs as U,bt as Ba,bu as $a,D as Va,bv as Da,bw as Oa,bx as La,by as hn,bz as Na,bA as Ma,bB as ja,bC as xt,bD as mn,bE as ve,bF as _a,bG as za,bH as Wa,bI as Ha,bJ as Ae,bK as Ce,bL as yn,af as We,bM as Ua,bN as qa,bO as Ga,bP as At,bQ as fn,bR as ye,bS as ht,bT as Ya,ac as Et,bU as Sn,a3 as Ee,bV as Ka,ad as bn,bW as Ie,bX as Ja,a5 as Xa,bY as vn,bZ as ke,b_ as Cn,b$ as mt,l as Z,c0 as He,b as wn,d as de,e as Tn,U as It,ak as Qe,al as xn,c1 as Qa,S as Rt,h as kt,i as Ft,c2 as Za,W as An,c3 as En,c4 as In,c5 as Rn,c6 as er,c7 as kn,au as tr,c8 as Re,c9 as Lt,ca as nr,cb as Fn,cc as yt,cd as Pn,R as ar,Q as rr,X as or,g as Bn,k as $n,ce as sr,cf as ir,V as Nt,I as lr,cg as cr,ch as dr,ci as Mt,cj as ur,ck as Vn,cl as pr,ae as gr,cm as jt,cn as hr,co as mr,cp as yr,cq as fr,cr as Sr,cs as br,M as vr,ct as Cr,cu as wr,cv as Tr,cw as xr,cx as Ar}from"./index-54a8dd7a.js";import{C as Me,f as Er,u as Dn,U as On,E as Ln,a as Nn,V as Ir,F as Rr,b as kr,c as Fr}from"./FeatureArchiveDialog-57c6d9ed.js";import{S as Pr}from"./StrategyItemContainer-66556bf6.js";import{E as Br}from"./ExpandMore-46f830cb.js";import{v as rt}from"./v4-a960c1f4.js";function $r(e){return aa("MuiCardContent",e)}ra("MuiCardContent",["root"]);const Vr=["className","component"],Dr=e=>{const{classes:n}=e;return la({root:["root"]},$r,n)},Or=p("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),Lr=m.forwardRef(function(n,a){const r=oa({props:n,name:"MuiCardContent"}),{className:o,component:l="div"}=r,s=sa(r,Vr),i=Vt({},r,{component:l}),d=Dr(i);return t(Or,Vt({as:l,className:ia(d.root,o),ownerState:i,ref:a},s))}),Nr=Lr,Mr=qe(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"),jr=qe(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"),_r=qe(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"),zr=qe(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"),Wr=p("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Hr=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=_(e,n);return a.name?t(Wr,{children:t(ca,{title:"Event log",project:e,feature:n,displayInline:!0})}):null},Ze=(e,n={})=>{const a=async()=>{const u=Pe(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Ge("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:o,error:l}=da(Boolean(e),{tags:[]},r,a,n),[s,i]=m.useState(!l&&!o),d=()=>{bt(r)};return m.useEffect(()=>{i(!l&&!o)},[o,l]),{tags:(o==null?void 0:o.tags)||[],error:l,loading:s,refetch:d}},Ur=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.primary.main,display:"flex",flexDirection:"column",marginRight:e.spacing(2),marginTop:e.spacing(2),[e.breakpoints.down(800)]:{width:"100%",maxWidth:"none"}})),qr=p(Be)(({theme:e})=>({marginRight:e.spacing(.5),marginTop:e.spacing(1),backgroundColor:e.palette.text.tertiaryContrast,fontSize:e.fontSizes.smallBody})),Gr=p(ua)(({theme:e})=>({color:e.palette.primary.light,"&:hover":{color:e.palette.primary.light}})),Yr=({projectId:e,...n})=>{const[a,r]=m.useState(!1),[o,l]=m.useState({value:"",type:""}),s=k("featureId"),{tags:i,refetch:d}=Ze(s),{tagTypes:u}=cn(),{deleteTagFromFeature:g}=ce(),{setToastData:h,setToastApiError:b}=K(),{hasAccess:y}=m.useContext($e),T=y(fe,e),w=async()=>{try{await g(s,o.type,o.value),d(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(v){b(j(v))}},S=v=>{let x=u.find($=>$.name===v);const A={width:"20px",height:"20px",marginRight:"5px"};if(x&&x.icon)switch(x.name){case"slack":return t("img",{style:A,alt:"Slack",src:at(ha)});case"jira":return t("img",{style:A,alt:"JIRA",src:at(ga)});case"webhook":return t("img",{style:A,alt:"Webhook",src:at(pa)});default:return t(dn,{})}else return t("span",{children:v[0].toUpperCase()})},f=v=>t(qr,{icon:S(v.type),"data-loading":!0,label:v.value,deleteIcon:t(Gr,{titleAccess:"Remove"}),onDelete:T?()=>{r(!0),l({type:v.type,value:v.value})}:void 0},`${v.type}:${v.value}`);return c(Ur,{...n,children:[t(ie,{open:a,onClose:()=>{r(!1),l({type:"",value:""})},onClick:()=>{r(!1),w(),l({type:"",value:""})},title:"Are you sure you want to delete this tag?"}),t("div",{children:t(E,{condition:i.length>0,show:i.map(f),elseShow:t("p",{"data-loading":!0,children:"No tags to display"})})})]})},Kr=p("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"}})),Jr=p("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Xr=p("div")(({theme:e})=>({padding:"0 1.5rem 1.5rem 1.5rem",borderTop:`1px solid ${e.palette.divider}`})),Qr=p("div")({display:"flex",alignItems:"center"}),Zr=p("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),eo=p("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),_t=p("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),zt=p("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.text.tertiaryContrast})),to=()=>{const{uiConfig:e}=Te(),n=k("projectId"),a=k("featureId"),{tags:r}=Ze(a),{feature:o}=_(n,a),{project:l,description:s,type:i}=o,d=ya(i);return c(Kr,{children:[c(Jr,{children:[c(Qr,{"data-loading":!0,children:[t(d,{sx:u=>({marginRight:u.spacing(2),height:"40px",width:"40px",fill:u.palette.text.tertiaryContrast})})," ",c(Zr,{children:[ma(i||"")," toggle"]})]}),c(eo,{children:[c(_t,{"data-loading":!0,children:["Project: ",l]}),t(E,{condition:Boolean(s),show:c(_t,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(zt,{children:[t("p",{children:s}),t(ne,{projectId:n,permission:fe,component:se,to:`/projects/${n}/features/${a}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:u=>({color:u.palette.text.tertiaryContrast})})})]})]}),elseShow:t("span",{"data-loading":!0,children:c(zt,{children:["No description."," ",t(ne,{projectId:n,permission:fe,component:se,to:`/projects/${n}/features/${a}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:u=>({color:u.palette.text.tertiaryContrast})})})]})})})]})]}),t(E,{condition:r.length>0&&!Boolean(e.flags.variantsPerEnvironment),show:t(Xr,{children:t(Yr,{projectId:n})})})]})},Wt={lastHourUsage:[],seenApplications:[]},no=(e,n,a={})=>{const r=async()=>{const g=Pe(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Ge("feature metrics"));return h.ok?h.json():Wt},o=`${e}_${n}_metrics`,{data:l,error:s}=vt(o,r,{...a}),[i,d]=m.useState(!s&&!l),u=()=>{bt(o)};return m.useEffect(()=>{d(!s&&!l)},[l,s]),{metrics:l||Wt,error:s,loading:i,refetch:u,FEATURE_METRICS_CACHE_KEY:o}},ao=e=>({yes:0,no:0,environment:e,timestamp:""}),ro=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||ao(a.name)),oo=({enabled:e,className:n})=>{const a=Ye(),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(_r,{style:{fill:"#fff",width:"16px",height:"16px"},titleAccess:r})})},Mn=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),so=({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(Mn,{})}),io=p("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),lo=({onRemove:e,onClose:n,isOpen:a})=>c(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(Mn,{}),t(io,{children:t(H,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(H,{fontWeight:"bold",children:"Remove strategy"})]}),co=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{deleteStrategyFromFeature:o}=De(),{setToastData:l,setToastApiError:s}=K(),i=xe(),{refetchFeature:d}=_(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,r),l({title:"Strategy deleted",type:"success"}),d(),i(un(e,n))}catch(h){s(j(h))}}},uo=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{addChange:o}=Ct(),{refetch:l}=Oe(e),{setToastData:s,setToastApiError:i}=K();return async u=>{try{u.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:r}}),s({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(j(g))}}},po=({projectId:e,featureId:n,environmentId:a,strategyId:r,disabled:o,icon:l})=>{const[s,i]=m.useState(!1),{isChangeRequestConfigured:d}=pe(e),u=co({featureId:n,projectId:e,strategyId:r,environmentId:a}),g=uo({featureId:n,projectId:e,strategyId:r,environmentId:a});return c(O,{children:[t(E,{condition:Boolean(l),show:t(ne,{onClick:()=>i(!0),projectId:e,environmentId:a,disabled:o,permission:Dt,"data-testid":Ot,tooltipProps:{title:"Remove strategy"},type:"button",children:t(Ve,{})}),elseShow:t(ge,{onClick:()=>i(!0),projectId:e,environmentId:a,disabled:o,permission:Dt,"data-testid":Ot,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(E,{condition:d(a),show:t(lo,{isOpen:s,onClose:()=>i(!1),onRemove:async h=>{await g(h),i(!1)}}),elseShow:t(so,{isOpen:s,onClose:()=>i(!1),onRemove:u})})]})},go=e=>(n,a,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,a,r));var ho=fa(vt,go);const jn=(e,n)=>{const{refetchFeature:a}=_(e,n),r=Sa(e,n),{data:o,error:l,mutate:s}=ho(["useFeatureImmutable",r],()=>ba(r)),i=m.useCallback(async()=>{await s(),await a()},[s,a]);return{feature:(o==null?void 0:o.body)||va,refetchFeature:i,loading:!l&&!o,status:o==null?void 0:o.status,error:l}},Pt=(e,n,a)=>{const{setToastData:r,setToastApiError:o}=K(),{addChange:l}=Ct(),{refetch:s}=Oe(e),[i,d]=m.useState({isOpen:!1}),u=m.useCallback((T,w,S)=>{d({featureName:n,environment:T,fromEnvironment:S,strategy:w,isOpen:!0})},[]),g=m.useCallback((T,w,S)=>{d({featureName:n,environment:T,fromEnvironment:S,strategies:w,isOpen:!0})},[]),h=m.useCallback(()=>{d({isOpen:!1})},[]),b=m.useCallback(async()=>{try{await l(e,i.environment,{feature:i.featureName,action:a,payload:i.strategy}),s(),d({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(T){o(j(T)),d({isOpen:!1})}},[l]),y=m.useCallback(async()=>{try{await Promise.all(i.strategies.map(T=>l(e,i.environment,{feature:i.featureName,action:a,payload:T}))),s(),d({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(T){o(j(T)),d({isOpen:!1})}},[l]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:i}},mo=({payload:e,fromEnvironment:n,environment:a})=>c(H,{children:[c("strong",{children:["Copy ",Le((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),yo=({environmentId:e,environments:n,strategy:a})=>{const r=k("projectId"),o=k("featureId"),[l,s]=m.useState(null),i=Boolean(l),{addStrategyToFeature:d}=De(),{setToastData:u,setToastApiError:g}=K(),{refetchFeature:h}=_(r,o),{refetchFeature:b}=jn(r,o),y=()=>{s(null)},T=Ca(r),{isChangeRequestConfigured:w}=pe(r),{changeRequestDialogDetails:S,onChangeRequestAddStrategyClose:f,onChangeRequestAddStrategy:v,onChangeRequestAddStrategyConfirm:x}=Pt(r,o,"addStrategy"),A=async F=>{const{id:M,...D}={...a,targetEnvironment:F};if(w(F)){await v(F,{id:M,...D},e);return}try{await d(r,o,F,a),h(),b(),u({title:"Strategy created",text:`Successfully copied a strategy to ${F}`,type:"success"})}catch(Y){g(j(Y))}y()},$=n.some(F=>T(be,F));return c("div",{children:[t(Me,{isOpen:S.isOpen,onClose:f,environment:S==null?void 0:S.environment,onConfirm:x,messageComponent:t(mo,{fromEnvironment:S.fromEnvironment,payload:S.strategy})}),t(le,{title:`Copy to another environment${$?"":" (Access denied)"}`,children:t("div",{children:t(Ne,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:F=>{s(F.currentTarget)},"data-testid":wa,disabled:!$,children:t(Ta,{})})})}),t(Ke,{id:"basic-menu",anchorEl:l,open:i,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(F=>{const M=T(be,F);return t(le,{title:M?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Je,{onClick:()=>A(F),disabled:!M,children:[t(E,{condition:!M,show:t(pn,{children:t(gn,{fontSize:"small"})})}),c(wt,{children:["Copy to ",F]})]})})},F)})})]})},fo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:r,otherEnvironments:o,orderNumber:l,headerChildren:s})=>{const i=k("projectId"),d=k("featureId"),u=xa(i,d,e,n.id);return t(Pr,{strategy:n,onDragStart:a,onDragEnd:r,orderNumber:l,actions:c(O,{children:[s,t(E,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(yo,{environmentId:e,environments:o,strategy:n})}),t(ne,{permission:Aa,environmentId:e,projectId:i,component:se,to:u,tooltipProps:{title:"Edit strategy"},children:t(Se,{})}),t(po,{projectId:i,featureId:d,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(Ea,{strategy:n})})},So=(e,n,a,r)=>{const{data:o}=Oe(e),l=o==null?void 0:o.find(d=>d.environment===a),s=l==null?void 0:l.features.find(d=>d.name===n);return s==null?void 0:s.changes.find(d=>d.action==="updateStrategy"||d.action==="deleteStrategy"?d.payload.id===r:!1)},bo=({strategy:e,index:n,environmentName:a,otherEnvironments:r,isDragging:o,onDragStartRef:l,onDragOver:s,onDragEnd:i})=>{const d=k("projectId"),u=k("featureId"),g=m.useRef(null),h=So(d,u,a,e.id);return c(Q,{ref:g,onDragOver:s(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(Ia,{text:"OR"})}),t(fo,{strategy:e,environmentId:a,otherEnvironments:r,onDragStart:l(g,n),onDragEnd:i,orderNumber:n+1,headerChildren:t(vo,{change:h})})]},e.id)},vo=({change:e})=>{const n=Ye();return ue(n.breakpoints.down("sm"))?null:c(Q,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(gt,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(gt,{color:"error",children:"Deleted in draft"})})]})},Co=p("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=p("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})),_n=({children:e})=>t(Co,{children:t(wo,{children:e})}),To=({environmentId:e,environments:n,onClick:a})=>{const r=k("projectId"),[o,l]=m.useState(null),s=Boolean(o),{hasAccess:i}=m.useContext($e),d=n.some(u=>i(be,r,u));return c("div",{children:[t(le,{title:d?"":"(Access denied)",children:t("div",{children:t(me,{id:`copy-all-strategies-${e}`,"aria-controls":s?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:u=>{l(u.currentTarget)},disabled:!d,variant:"outlined",children:"Copy from another environment"})})}),t(Ke,{id:"basic-menu",anchorEl:o,open:s,onClose:()=>{l(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=i(be,r,u);return t(le,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Je,{onClick:()=>a(u),disabled:!g,children:[t(E,{condition:!g,show:t(pn,{children:t(gn,{fontSize:"small"})})}),c(wt,{children:["Copy from ",u]})]})})},u)})})]})},xo=p("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Ao=({payload:e,fromEnvironment:n,environment:a})=>c(xo,{children:[t(H,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>c(H,{children:[c("strong",{children:[Le((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),c(H,{children:["from ",n," to ",a]})]}),Eo=({payload:e,environment:n})=>c(O,{children:[t(H,{component:"span",children:"Add "}),c("strong",{children:[Le((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),Io=p(Ra)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),Ht=({title:e,children:n,featureId:a,projectId:r,environmentId:o,strategy:l,Icon:s,onAfterAddStrategy:i})=>{const{addStrategyToFeature:d}=De(),{setToastApiError:u}=K(),{isChangeRequestConfigured:g}=pe(r),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:y,onChangeRequestAddStrategyClose:T}=Pt(r,a,"addStrategy");return c(O,{children:[t(Io,{variant:"outlined",children:c(Nr,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(H,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(s,{color:"disabled",sx:{mr:1}})," ",e]}),t(H,{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(ge,{permission:be,projectId:r,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,l):(await d(r,a,o,l),i())}catch(S){u(j(S))}},children:"Use template"})})]})}),t(Me,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Eo,{environment:o,payload:h.strategy})})]})},Ro=p("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}})),ko=p("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Fo=p(Xe)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Po=p(se)(({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}})),Bo=({projectId:e,featureId:n,environmentId:a,strategy:r})=>{const o=_e(r.name),l=Le(r.name),s=Er(e,n,a,r.name);return c(Po,{to:s,children:[t(Ro,{children:t(o,{})}),c("div",{children:[t(Fo,{text:r.displayName||l,maxWidth:"200",maxLength:25}),t(ko,{children:r.description})]})]})},$o=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:r}=ka(),o=m.useMemo(()=>r.filter(l=>!l.deprecated),[r]);return t(Tt,{dense:!0,children:o.map(l=>t(ze,{children:t(Bo,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))})},ft=({label:e,projectId:n,featureId:a,environmentId:r,variant:o,matchWidth:l})=>{const[s,i]=m.useState(),d=Boolean(s),u=d?"FeatureStrategyMenuPopover":void 0,g=()=>{i(void 0)};return c("div",{onClick:b=>b.stopPropagation(),children:[t(ge,{permission:be,projectId:n,environmentId:r,onClick:b=>{i(b.currentTarget)},"aria-labelledby":u,variant:o,sx:{minWidth:l?"282px":"auto"},children:e}),t(Fa,{id:u,open:d,anchorEl:s,onClose:g,onClick:g,children:t($o,{projectId:n,featureId:a,environmentId:r})})]})},Vo=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Do=p("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Oo=p("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3)})),Lo=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:r}=De(),{setToastData:o,setToastApiError:l}=K(),{refetchFeature:s}=_(e,n),{refetchFeature:i}=jn(e,n),{feature:d}=_(e,n),u=d==null?void 0:d.environments.filter(v=>v.name!==a&&v.strategies&&v.strategies.length>0),{isChangeRequestConfigured:g}=pe(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:y,onChangeRequestAddStrategyClose:T}=Pt(e,n,"addStrategy"),w=(v=!1)=>{s(),i(),o({title:v?"Strategies created":"Strategy created",text:v?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},S=async v=>{var A;const x=((A=u==null?void 0:u.find($=>$.name===v))==null?void 0:A.strategies)||[];if(g(a)){await b(a,x,v);return}try{await Promise.all(x.map($=>{const{id:F,...M}={...$,environment:a};return r(e,n,a,M)})),w(!0)}catch($){l(j($))}},f=u&&u.length>0;return c(O,{children:[t(Me,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Ao,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(Vo,{children:[t(Do,{children:"You have not defined any strategies yet."}),c(Oo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(se,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Q,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(ft,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:f}),t(E,{condition:f,show:t(To,{environmentId:a,environments:u.map(v=>v.name),onClick:S})})]}),t(Q,{sx:{width:"100%",mt:3},children:t(_n,{children:"Or use a strategy template"})}),c(Q,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(Ht,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:w,Icon:_e("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(Ht,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:w,Icon:_e("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:d.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},No=p("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Mo=p("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),jo=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const r=k("projectId"),o=k("featureId"),{setStrategiesSortOrder:l}=De(),{setToastData:s,setToastApiError:i}=K(),{refetchFeature:d}=_(r,o),[u,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 f=>{try{await l(r,o,e.name,f),d(),s({title:"Order of strategies updated",type:"success"})}catch(v){i(j(v))}},T=(f,v)=>x=>{var A;b({id:u[v].id,index:v,height:((A=f.current)==null?void 0:A.offsetHeight)||0}),f!=null&&f.current&&(x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/html",f.current.outerHTML),x.dataTransfer.setDragImage(f.current,20,20))},w=f=>(v,x)=>A=>{if(h===null||v.current===null||h.index===x||f===h.id)return;const{top:$,bottom:F}=v.current.getBoundingClientRect(),M=A.clientY-$<h.height,D=F-A.clientY<h.height,Y=h.index>x;if(M&&Y||D&&!Y){const q=[...u],G=q.splice(h.index,1)[0];q.splice(x,0,G),g(q),b({...h,index:x})}},S=()=>{b(null),y(u.map((f,v)=>({id:f.id,sortOrder:v})))};return t(No,{children:c(Mo,{children:[t(E,{condition:u.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:u.length>0,show:t(O,{children:u.map((f,v)=>t(bo,{strategy:f,index:v,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===f.id,onDragStartRef:T,onDragOver:w(f.id),onDragEnd:S},f.id))}),elseShow:t(Lo,{projectId:r,featureId:o,environmentId:e.name})})]})})},zn=(e,n)=>e===0?0:Math.round(n/e*100);var et={},tt={};Object.defineProperty(tt,"__esModule",{value:!0});tt.defaultOptions=void 0;tt.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var we={};Object.defineProperty(we,"__esModule",{value:!0});we.roundTo=we.parseValue=void 0;function _o(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}we.parseValue=_o;function zo(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))}we.roundTo=zo;Object.defineProperty(et,"__esModule",{value:!0});et.millify=void 0;const ot=tt,Ut=we,qt=1e3;function*Gt(e){let n=qt;for(;;){const a=e/n;if(a<1)return;yield a,n*=qt}}function Wn(e,n){var a;const r=n?Object.assign(Object.assign({},ot.defaultOptions),n):ot.defaultOptions;if(!Array.isArray(r.units)||!r.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Ut.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const l=o<0?"-":"";o=Math.abs(o);let s=0;for(const y of Gt(o))o=y,s+=1;if(s>=r.units.length)return e.toString();let d=Ut.roundTo(o,r.precision);for(const y of Gt(d))d=y,s+=1;const u=(a=r.units[s])!==null&&a!==void 0?a:"",g=r.lowercase?u.toLowerCase():u,h=r.space?" ":"",b=d.toString().replace(ot.defaultOptions.decimalSeparator,r.decimalSeparator);return`${l}${b}${h}${g}`}et.millify=Wn;var Wo=et.default=Wn;const Ue=({value:e,threshold:n=1e6,precision:a=2})=>{let r,o=!1;e<n?r=e.toLocaleString():(r=Wo(e,{precision:a}),o=!0);const l=t("span",{"data-testid":Pa,children:r});return t(E,{condition:o,show:t(le,{title:e.toLocaleString(),arrow:!0,children:l}),elseShow:l})},st=p("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),it=p("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),lt=p("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),ct=p("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})),Hn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:r,tableSectionId:o})=>{const l=a===1?"in the last hour":`in the last ${a} hours`;return c(U,{container:!0,spacing:2,id:r,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Exposure"}),t(lt,{children:t(Ue,{value:e})}),c(ct,{children:["Total exposure of the feature in the environment"," ",l,"."]})]})}),t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Exposure %"}),c(lt,{children:[zn(e+n,e),"%"]}),c(ct,{children:["% total exposure of the feature in the environment"," ",l,"."]})]})}),t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Requests"}),t(lt,{children:t(Ue,{value:e+n})}),c(ct,{children:["Total requests for the feature in the environment"," ",l,"."]})]})})]})},Ho=({environmentMetric:e})=>e?c(O,{children:[t(_n,{children:"Feature toggle exposure"}),t("div",{children:t(Hn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Yt=p("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Kt=p("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Jt=p("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Xt=p("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Uo=p(Ba)(({theme:e})=>({fill:e.palette.standaloneBackground,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),qo=p("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),Go=({environmentMetric:e,disabled:n=!1})=>{const a=$a();if(!e)return null;const r=e.yes+e.no,o=zn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Yt,{children:[c(Kt,{children:[c(Jt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),c(Xt,{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(Uo,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Yt,{children:[c(Kt,{children:[c(Jt,{children:[o,"%"]}),c(Xt,{children:["The feature has been requested"," ",c("b",{children:[t(Ue,{value:r})," times"]})," ","and exposed"," ",c("b",{children:[t(Ue,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(qo,{"data-loading":!0,children:t(Va,{percentage:o,size:"3rem"})})]})},Yo=({strategyName:e})=>{const n=_e(e);return t(le,{title:Le(e),arrow:!0,children:t(Ko,{children:t(n,{})})})},Ko=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.inactiveIcon,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),Jo=({strategies:e})=>e!=null&&e.length?t(Xo,{"aria-label":"Feature strategies",children:e.map(n=>t(Qo,{children:t(Yo,{strategyName:n.name})},n.id))}):null,Xo=p("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Qo=p("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Zo=p("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})),es=p(Da)({boxShadow:"none",background:"none"}),ts=p(Oa)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),ns=p(La,{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)}})),as=p(jo)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),rs=p("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})),os=p("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),ss=p(oo)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),is=p(Xe)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),ls=p("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),cs=({env:e})=>{var u;const n=k("projectId"),a=k("featureId"),{metrics:r}=no(n,a),{feature:o}=_(n,a),{value:l}=hn(),i=ro(o==null?void 0:o.environments,r).find(g=>g.environment===e.name),d=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!Boolean(new Set(l.hiddenEnvironments).has(e.name)),show:t(Zo,{enabled:e.enabled,children:c(es,{"data-testid":`${Na}_${e.name}`,children:[c(ts,{expandIcon:t(Br,{titleAccess:"Toggle"}),children:[c(rs,{"data-loading":!0,enabled:e.enabled,children:[c(os,{children:[t(ss,{enabled:e.enabled}),t("div",{children:t(is,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(Be,{size:"small",variant:"outlined",label:"Disabled",sx:{ml:1}})})]}),c(ls,{children:[t(ft,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(Jo,{strategies:d==null?void 0:d.strategies})]})]}),t(Go,{environmentMetric:i,disabled:!e.enabled})]}),c(ns,{enabled:e.enabled,children:[t(as,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((u=d==null?void 0:d.strategies)==null?void 0:u.length)||0)>0,show:c(O,{children:[t(Q,{sx:{display:"flex",justifyContent:"center",py:1},children:t(ft,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(Ho,{environmentMetric:i})]})})]})]})})})},ds=()=>{const e=k("projectId"),n=k("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(cs,{env:o},o.name))})},us=p(Ne,{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}})),Un=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(us,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(Ma,{}),elseShow:t(ja,{})})}),ps=p("div")({display:"flex",alignItems:"center"}),gs=p("label")({display:"inline-flex",alignItems:"center",cursor:"pointer"}),hs=({env:e,callback:n,text:a,showInfoBox:r,hiddenEnvironments:o,setHiddenEnvironments:l})=>{const s=k("projectId"),i=k("featureId"),{toggleFeatureEnvironmentOn:d,toggleFeatureEnvironmentOff:u}=ce(),{refetchFeature:g}=_(s,i),{setToastData:h,setToastApiError:b}=K(),{isChangeRequestConfigured:y}=pe(s),{onChangeRequestToggle:T,onChangeRequestToggleClose:w,onChangeRequestToggleConfirm:S,changeRequestDialogDetails:f}=Dn(s),v=async()=>{try{await d(s,i,e.name),h({type:"success",title:`Available in ${e.name}`,text:`${i} is now available in ${e.name} based on its defined strategies.`}),g(),n&&n()}catch(F){F instanceof Error&&F.message===Ln?r():b(j(F))}},x=async()=>{try{await u(s,i,e.name),h({type:"success",title:`Unavailable in ${e.name}`,text:`${i} is unavailable in ${e.name} and its strategies will no longer have any effect.`}),g(),n&&n()}catch(F){b(j(F))}},A=async F=>{if(y(e.name)){F.preventDefault(),T(i,e.name,!e.enabled);return}if(e.enabled){await x();return}await v()};let $=a||c(O,{children:[" ",c("span",{"data-loading":!0,children:[e.enabled?"enabled":"disabled"," in"]})," ",t(Xe,{text:e.name,maxWidth:"120",maxLength:15})]});return c(ps,{children:[c(gs,{children:[t(xt,{permission:mn,projectId:s,checked:e.enabled,onChange:A,environmentId:e.name}),$]}),t(Un,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:l}),t(Me,{isOpen:f.isOpen,onClose:w,environment:f==null?void 0:f.environment,onConfirm:S,messageComponent:t(On,{enabled:f==null?void 0:f.enabled,featureName:f==null?void 0:f.featureName,environment:f.environment})})]})},ms=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",padding:"1.5rem",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),ys=p("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0,marginBottom:"0.5rem","& > :last-child":{position:"relative",top:1}})),fs=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=k("projectId"),r=k("featureId"),{feature:o}=_(a,r);ce();const[l,s]=m.useState(!1),[i,d]=m.useState(""),u=()=>{s(!1)};return c(ms,{"data-testid":"feature-toggle-status",children:[c(ys,{"data-loading":!0,children:["Feature toggle status",t(ve,{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"})]}),(()=>o==null?void 0:o.environments.map(h=>t(hs,{env:h,hiddenEnvironments:e,setHiddenEnvironments:n,showInfoBox:()=>{d(h.name),s(!0)}},h.name)))(),t(Nn,{open:l,onClose:u,projectId:a,featureId:r,environmentName:i})]})},Ss=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),bs=p("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),vs=({feature:e,header:n})=>{const{locationSettings:a}=_a();return c(Ss,{children:[n,c("div",{"data-loading":!0,children:[t(bs,{children:"Created at:"}),t("span",{children:za(Wa(e.createdAt),a.locale)})]})]})},Cs=p("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),ws=p("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Ts=({environment:e,callback:n,showInfoBox:a,children:r,hiddenEnvironments:o,setHiddenEnvironments:l})=>{const{name:s,enabled:i}=e,d=k("projectId"),u=k("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=ce(),{refetchFeature:b}=_(d,u),{setToastData:y,setToastApiError:T}=K(),{isChangeRequestConfigured:w}=pe(d),{onChangeRequestToggle:S,onChangeRequestToggleClose:f,onChangeRequestToggleConfirm:v,changeRequestDialogDetails:x}=Dn(d),A=async()=>{try{await g(d,u,s),y({type:"success",title:`Available in ${s}`,text:`${u} is now available in ${s} based on its defined strategies.`}),b(),n&&n()}catch(D){D instanceof Error&&D.message===Ln?a():T(j(D))}},$=async()=>{try{await h(d,u,s),y({type:"success",title:`Unavailable in ${s}`,text:`${u} is unavailable in ${s} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(D){T(j(D))}},F=async D=>{if(w(s)){D.preventDefault(),S(u,s,!i);return}if(i){await $();return}await A()},M=c(O,{children:[" ",c("span",{"data-loading":!0,children:[i?"enabled":"disabled"," in"]})," ",t(Xe,{text:s,maxWidth:"120",maxLength:15})]});return c(Cs,{children:[c(ws,{children:[t(xt,{tooltip:i?`Disable feature in ${s}`:`Enable feature in ${s}`,permission:mn,projectId:d,checked:i,onChange:F,environmentId:s}),r??M]}),t(Un,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:l}),t(Me,{isOpen:x.isOpen,onClose:f,environment:x==null?void 0:x.environment,onConfirm:v,messageComponent:t(On,{enabled:x==null?void 0:x.enabled,featureName:x==null?void 0:x.featureName,environment:x.environment})})]})},xs=p("div")(({theme:e})=>({padding:e.spacing(3)})),As=p("div")(()=>({display:"flex",flexDirection:"column"})),Es=p("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Is=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Qt=p("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Rs=p(Ha)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),ks=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:r})=>{const[o,l]=m.useState(!1),[s,i]=m.useState(""),d=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return c(xs,{children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],b=h.length>0&&c(O,{children:[t(Qt,{}),t(le,{title:"View variants",arrow:!0,describeChild:!0,children:t(Rs,{component:se,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),y=u.enabled&&h.length==0&&d;return t(Ts,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:r,showInfoBox:()=>{i(u.name),l(!0)},children:c(As,{children:[t(Es,{children:u.name}),c(Is,{children:[g,b,t(E,{condition:y,show:c(O,{children:[t(Qt,{}),t(Ir,{})]})})]})]})},u.name)}),t(Nn,{open:o,onClose:()=>l(!1),projectId:e.project,featureId:e.name,environmentName:s})]})},Fs=({value:e,onChange:n,...a})=>{const{tagTypes:r}=cn(),o=r.map(l=>({key:l.name,label:l.name,title:l.name}));return t(O,{children:t(Ae,{label:"Tag type",id:"tag-select",options:o,value:e,onChange:n,...a})})},Ps=p(Ce)(()=>({width:"100%"})),Bs=p("section")(({theme:e})=>({["& > *"]:{margin:"0.5rem 0"}})),qn=({open:e,setOpen:n})=>{const a={type:"simple",value:""},r=k("featureId"),{addTagToFeature:o,loading:l}=ce(),{tags:s,refetch:i}=Ze(r),[d,u]=m.useState({tagError:""}),{setToastData:g}=K(),[h,b]=m.useState(a),y=()=>{n(!1),u({tagError:""}),b(a)},T=async A=>{A.preventDefault(),h.type||(h.type="simple");try{await o(r,h),n(!1),b(a),i(),g({type:"success",title:"Added tag to toggle",text:"We successfully added a tag to your toggle",confetti:!0})}catch($){const F=j($);u({tagError:F})}},w=A=>A.length,S=A=>!s.some(({type:$,value:F})=>$===A.type&&F===A.value),f=w(h.value)&&S(h),v=(A,$)=>{u({tagError:""});const F={...h,[A]:yn($)};S(F)||u({tagError:"Tag already exists for this feature toggle."}),b(F)},x="add-tag-form";return t(O,{children:t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Add tag",title:"Add tags to feature toggle",onClick:T,disabledPrimaryButton:l||!f,onClose:y,formId:x,children:c(O,{children:[t(H,{paragraph:!0,children:"Tags allow you to group features together"}),t("form",{id:x,onSubmit:T,children:c(Bs,{children:[t(Fs,{autoFocus:!0,name:"type",value:h.type,onChange:A=>v("type",A)}),t("br",{}),t(Ps,{label:"Value",name:"value",placeholder:"Your tag",value:h.value,error:Boolean(d.tagError),errorText:d.tagError,onChange:A=>v("value",A.target.value),required:!0})]})})]})})})},$s=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Vs=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Ds=p(Be)(({theme:e})=>({fontSize:e.fontSizes.smallBody,".MuiChip-deleteIcon":{color:e.palette.neutral.main}})),Os=p(We)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Ls=p(me)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Ns=({feature:e,header:n})=>{const{tags:a,refetch:r}=Ze(e.name),{deleteTagFromFeature:o}=ce(),[l,s]=m.useState(!1),[i,d]=m.useState(!1),[u,g]=m.useState(),{setToastData:h,setToastApiError:b}=K(),{hasAccess:y}=m.useContext($e),T=y(fe,e.project),w=async()=>{if(u)try{await o(e.name,u.type,u.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(S){b(j(S))}};return c($s,{children:[n,t(Vs,{children:a.map(S=>{const f=`${S.type}:${S.value}`;return t(Ds,{label:f,deleteIcon:t(Ua,{titleAccess:"Remove"}),onDelete:T?()=>{d(!0),g(S)}:void 0},f)})}),t(E,{condition:T,show:c(O,{children:[t(E,{condition:a.length>0,show:t(Os,{})}),t(Ls,{"data-loading":!0,variant:"outlined",startIcon:t(qa,{}),onClick:()=>s(!0),children:"Add new tag"})]})}),t(qn,{open:l,setOpen:s}),c(ie,{open:i,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),g(void 0)},onClick:()=>{d(!1),w(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},Ms=p("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"}})),dt=p("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}})),js=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=k("projectId"),r=k("featureId"),{feature:o}=_(a,r);return c(Ms,{children:[t(ks,{header:c(dt,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:l})=>l).length,")",t(ve,{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(We,{}),t(vs,{header:t(dt,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(We,{}),t(Ns,{header:t(dt,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},_s=()=>{const{trackEvent:e}=Ga(),{value:n,setValue:a}=hn(),[r,o]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:s=>{a(i=>{const d=new Set(i.hiddenEnvironments);return d.has(s)?(d.delete(s),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(d.add(s),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(d),{...n,hiddenEnvironments:d}})}}},zs=p("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Ws=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),Hs=()=>{const{uiConfig:e}=Te(),n=xe(),a=k("projectId"),r=k("featureId"),o=un(a,r),{hiddenEnvironments:l,setHiddenEnvironments:s}=_s(),i=()=>n(o);return At(r),c(zs,{children:[c("div",{children:[t(to,{}),t(E,{condition:Boolean(e.flags.variantsPerEnvironment),show:t(js,{hiddenEnvironments:l,setHiddenEnvironments:s}),elseShow:t(fs,{hiddenEnvironments:l,setHiddenEnvironments:s})})]}),t(Ws,{children:t(ds,{})}),c(fn,{children:[t(ye,{path:"strategies/create",element:t(ht,{label:"Create feature strategy",onClose:i,open:!0,children:t(Rr,{})})}),t(ye,{path:"strategies/edit",element:t(ht,{label:"Edit feature strategy",onClose:i,open:!0,children:t(Ya,{})})})]})]})},Gn=({values:e=[],updateValues:n,placeholder:a="",error:r,...o})=>{const l=i=>{const u=i.target.value.split(/,\s?/).map(g=>g.trim());n(u)},s=i=>{if(i.key==="Backspace"){const d=i.target.value;if(d.endsWith(", ")){i.preventDefault();const u=d.slice(0,-2);n(u.split(/,\s*/))}}};return t(Et,{...o,error:r,placeholder:a,value:e?e.join(", "):"",onKeyDown:s,onChange:l,style:{width:"100%"},variant:"outlined",size:"small"})},Us=({overrides:e,overridesDispatch:n})=>{const{classes:a}=Sn(),{context:r}=Ee(),o=r.map(({name:i})=>({key:i,label:i})),l=i=>d=>{n({type:"UPDATE_VALUES_AT",payload:[i,d]})},s=i=>(d,u)=>{d==null||d.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[i,u||[]]})};return t(O,{children:e.map((i,d)=>{var b;const u=r.find(y=>y.name===i.contextName),g=((b=u==null?void 0:u.legalValues)==null?void 0:b.map(({value:y})=>y))||[],h=i.values.filter(y=>g.includes(y));return c(U,{container:!0,alignItems:"center",children:[t(U,{item:!0,md:3,sm:3,xs:3,sx:y=>({marginRight:y.spacing(1)}),children:t(Ae,{name:"contextName",label:"Context Field",value:i.contextName,options:o,classes:{root:Ka(a.fullWidth)},onChange:y=>{n({type:"UPDATE_TYPE_AT",payload:[d,y]})}})}),t(U,{md:7,sm:7,xs:6,item:!0,children:t(E,{condition:Boolean(g&&g.length>0),show:t(bn,{multiple:!0,id:`override-select-${d}`,isOptionEqualToValue:(y,T)=>y===T,options:g,onChange:s(d),getOptionLabel:y=>y,value:h,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:y=>t(Et,{...y,variant:"outlined",label:"Legal values",style:{width:"100%"}})}),elseShow:t(Gn,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:i.values,updateValues:l(d)})})}),t(U,{item:!0,md:1,children:t(le,{title:"Remove",arrow:!0,children:t(Ne,{onClick:y=>{y.preventDefault(),n({type:"REMOVE",payload:d})},size:"large",children:t(Ve,{})})})})]},`override=${d}`)})})},qs=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((s,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((s,i)=>i===a?{...s,values:r}:s);case"UPDATE_TYPE_AT":const[o,l]=n.payload;return e.map((s,i)=>i===o?{...s,contextName:l}:s)}},Gs=(e=[])=>m.useReducer(qs,e),Ys=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],ut={type:"string",value:""},Ks=p("p")(({theme:e})=>({color:e.palette.error.main,fontSize:e.fontSizes.smallBody,position:"relative"})),Js=p(Ce)({maxWidth:350,width:"100%"}),Xs=p(U)(({theme:e})=>({marginBottom:e.spacing(1)})),Zt=p("p")(({theme:e})=>({display:"flex",alignItems:"center",gap:"1ch",marginBottom:e.spacing(2)})),Qs=p(Ae)({minWidth:"100px",width:"100%"}),Zs=({showDialog:e,closeDialog:n,save:a,editVariant:r,validateName:o,validateWeight:l,title:s,editing:i})=>{const[d,u]=m.useState({}),[g,h]=m.useState(ut),[b,y]=Gs([]),[T,w]=m.useState({}),{classes:S}=Sn(),f=k("projectId"),v=k("featureId"),{feature:x}=_(f,v),[A,$]=m.useState([]),{context:F}=Ee(),M=V=>{try{return JSON.parse(V),!0}catch{return w({payload:"Invalid JSON"}),!1}},D=()=>{r?(u({name:r.name,weight:String(r.weight/10),weightType:r.weightType||Ie.VARIABLE,stickiness:r.stickiness}),r.payload?h(r.payload):h(ut),r.overrides?y({type:"SET",payload:r.overrides}):y({type:"CLEAR"})):(u({}),h(ut),y({type:"CLEAR"})),w({})},Y=V=>$(mt(V));m.useEffect(()=>{x&&Y(x.variants)},[x.variants]),m.useEffect(()=>{D()},[r]);const q=V=>{const{name:R,value:z}=V.target;u({...d,[R]:yn(z)})},G=V=>{const{checked:R,name:z}=V.target,W=R?Ie.FIX:Ie.VARIABLE;u({...d,[z]:W})},ee=async V=>{w({}),V.preventDefault();const R=o(d.name);if(R){w(R);return}const z=l(d.weight);if(z){w(z);return}if(!(g.type==="json"&&!M(g.value)))try{const re={name:d.name,weight:Number(d.weight)*10,weightType:d.weightType,stickiness:d.stickiness,payload:g.value?g:void 0,overrides:b.map(ae=>({contextName:ae.contextName,values:ae.values})).filter(ae=>ae.values&&ae.values.length>0)};await a(re),D(),n()}catch(re){const ae=j(re);ae.includes("duplicate value")?w({name:"A variant with that name already exists."}):ae.includes("must be a number")?w({weight:"Weight must be a number"}):w({general:ae||"Could not add variant"})}},te=V=>R=>{w({payload:""}),h({...g,[V]:R})},B=V=>{V.preventDefault(),D(),n()},C=()=>{F.length>0&&y({type:"ADD",payload:{contextName:F[0].name,values:[]}})},I=d.weightType===Ie.FIX,N="add-feature-variant-form";return t(ie,{open:e,style:Ja,onClose:B,onClick:ee,primaryButtonText:"Save",secondaryButtonText:"Cancel",title:s,fullWidth:!0,maxWidth:"md",formId:N,children:c("form",{id:N,onSubmit:ee,className:S.contentSpacingY,children:[t(Ks,{children:T.general}),t(Js,{label:"Variant name",autoFocus:!0,name:"name",id:"variant-name",errorText:T.name,value:d.name||"",error:Boolean(T.name),required:!0,type:"name",disabled:i,onChange:q,"data-testid":"VARIANT_NAME_INPUT"}),t("br",{}),c(Xs,{container:!0,children:[t(E,{condition:i&&A.length>1||!i&&A.length>0,show:t(U,{item:!0,md:12,children:t(Xa,{children:t(vn,{control:t(xt,{permission:ke,projectId:f,name:"weightType",checked:I,"data-testid":"VARIANT_WEIGHT_CHECK",onChange:G}),label:"Custom percentage"})})})}),t(E,{condition:d.weightType===Ie.FIX,show:t(U,{item:!0,md:4,children:t(Ce,{id:"weight",label:"Variant weight",name:"weight","data-testid":"VARIANT_WEIGHT_INPUT",InputProps:{endAdornment:t(Cn,{position:"start",children:"%"})},sx:{marginRight:"0.8rem"},value:d.weight,error:Boolean(T.weight),errorText:T.weight,type:"number",disabled:!I,onChange:V=>{q(V)},"aria-valuemin":0,"aria-valuemax":100})})})]}),c(Zt,{children:[t("strong",{children:"Payload "}),t(ve,{tooltip:"Passed along with the the variant object."})]}),c(U,{container:!0,children:[t(U,{item:!0,md:2,sm:2,xs:4,children:t(Qs,{id:"variant-payload-type",name:"type",label:"Type",value:g.type,options:Ys,onChange:te("type")})}),t(U,{item:!0,md:8,sm:8,xs:6,children:t(Ce,{error:Boolean(T.payload),errorText:T.payload,name:"variant-payload-value",id:"variant-payload-value",label:"Value",multiline:g.type!=="string",rows:g.type==="string"?1:4,className:S.fullWidth,value:g.value,onChange:V=>te("value")(V.target.value),"data-testid":"VARIANT_PAYLOAD_VALUE",placeholder:g.type==="json"?'{ "hello": "world" }':""})})]}),t(E,{condition:b.length>0,show:c(Zt,{children:[t("strong",{children:"Overrides "}),t(ve,{tooltip:"Here you can specify which users should get this variant."})]})}),t(Us,{overrides:b,overridesDispatch:y}),t(me,{onClick:C,variant:"contained",color:"primary",children:"Add override"})]})})},ei=({show:e,onClick:n,onClose:a})=>t(ie,{title:"Are you sure you want to delete this variant?",open:e,primaryButtonText:"Delete variant",secondaryButtonText:"Cancel",onClick:n,onClose:a,children:t(he,{severity:"error",children:"Deleting this variant will change which variant users receive."})}),ti=({payload:e,overrides:n})=>c(O,{children:[t(E,{condition:Boolean(e),show:t(Z,{children:"Payload"})}),t(E,{condition:n&&n.length>0,show:t(Z,{children:"Overrides"})})]}),ni=({projectId:e,setDelDialog:n,variant:a,editVariant:r})=>c(Q,{style:{display:"flex",justifyContent:"flex-end"},"data-loading":!0,children:[t(ne,{size:"large","data-testid":`VARIANT_EDIT_BUTTON_${a.name}`,permission:ke,projectId:e,onClick:()=>r(a.name),children:t(Se,{})}),t(ne,{size:"large",permission:ke,"data-testid":`VARIANT_DELETE_BUTTON_${a.name}`,projectId:e,onClick:()=>n({show:!0,name:a.name}),children:t(Ve,{})})]}),ai=()=>{const{hasAccess:e}=m.useContext($e),n=k("projectId"),a=k("featureId"),{feature:r,refetchFeature:o,loading:l}=_(n,a),[s,i]=m.useState([]),[d,u]=m.useState(!1),{context:g}=Ee(),{setToastData:h,setToastApiError:b}=K(),{patchFeatureVariants:y}=ce(),[T,w]=m.useState({}),[S,f]=m.useState(!1),[v,x]=m.useState([]),[A,$]=m.useState({name:"",show:!1}),F=ue(He.breakpoints.down("md")),M=ue(He.breakpoints.down("lg"));m.useEffect(()=>{r&&R(r.variants)},[r.variants]),m.useEffect(()=>{const P=["default",...g.filter(L=>L.stickiness).map(L=>L.name)];x(P)},[g]);const D=e(ke,n),Y=m.useMemo(()=>l?Array(5).fill({name:"Context name",description:"Context description when loading"}):r.variants,[r.variants,l]),q=m.useCallback(P=>{const L={...s.find(J=>J.name===P)};w(L),u(!0),f(!0)},[s,w,u,f]),G=m.useMemo(()=>[{Header:"Name",accessor:"name",width:"25%",Cell:({row:{original:{name:P}}})=>t(Z,{"data-loading":!0,children:P}),sortType:"alphanumeric"},{Header:"Payload/Overrides",accessor:"data",Cell:({row:{original:{overrides:P,payload:L}}})=>t(ti,{overrides:P,payload:L}),disableSortBy:!0},{Header:"Weight",accessor:"weight",width:"20%",Cell:({row:{original:{name:P,weight:L}}})=>c(Z,{"data-testid":`VARIANT_WEIGHT_${P}`,children:[wn(L)," %"]}),sortType:"number"},{Header:"Type",accessor:"weightType",width:"20%",Cell:({row:{original:{weightType:P}}})=>t(Z,{children:P}),sortType:"alphanumeric"},{Header:"Actions",id:"Actions",align:"right",Cell:({row:{original:P}})=>t(ni,{editVariant:q,setDelDialog:$,variant:P,projectId:n}),width:150,disableSortBy:!0}],[n,q]),ee=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{getTableProps:te,getTableBodyProps:B,headerGroups:C,rows:I,prepareRow:N,setHiddenColumns:V}=de.useTable({columns:G,data:Y,initialState:ee,sortTypes:Tn,autoResetHiddenColumns:!1,autoResetGlobalFilter:!1,autoResetSortBy:!1,disableSortRemove:!0},de.useGlobalFilter,de.useSortBy);It([{condition:F,columns:["data"]},{condition:M,columns:["weightType"]}],V,G);const R=P=>i(mt(P)),z=()=>{f(!1),u(!1),w({})},W=()=>{if(!s||s.length<2)return null;const P=s[0].stickiness||"default",L=v.map(X=>({key:X,label:X}));return v.includes(P)||L.push({key:P,label:P}),c("section",{style:{paddingTop:"16px"},children:[t(Ae,{label:"Stickiness",options:L,value:P,onChange:X=>{re(X).catch(console.warn)}})," ",c("small",{style:{display:"block",marginTop:"0.5rem"},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"})]})]})},re=async P=>{const L=[...s].map(X=>({...X,stickiness:P})),J=$t(L);if(J.length!==0)try{await y(n,a,J),o(),h({title:"Updated variant",confetti:!0,type:"success",text:"Successfully updated variant stickiness"})}catch(X){b(j(X))}},ae=async P=>{let L=s.filter(J=>J.name!==P);try{await nt(L,"Successfully removed variant")}catch(J){b(j(J))}},Bt=async P=>{const L=mt(s),J=L.findIndex(X=>X.name===P.name);L[J]=P,await nt(L,"Successfully updated variant")},Xn=async P=>{let L="default";(s==null?void 0:s.length)>0&&(L=s[0].stickiness||"default"),P.stickiness=L,await nt([...s,P],"Successfully added a variant")},nt=async(P,L)=>{const J=En(P,1e3),X=$t(J);if(X.length!==0)try{await y(n,a,X),o(),h({title:"Updated variant",type:"success",text:L})}catch(na){b(j(na))}},Qn=P=>{if(!P)return{name:"Name is required"}},Zn=P=>{const L=parseInt(P);if(L>100||L<0)return{weight:"weight must be between 0 and 100"}},ea=ei({show:A.show,onClick:()=>{ae(A.name),$({name:"",show:!1}),h({title:"Deleted variant",type:"success",text:"Successfully deleted variant"})},onClose:()=>$({show:!1,name:""})}),$t=P=>In(r.variants,P),ta=()=>{u(!1),s.length===0?w({weight:1e3}):w({weightType:"variable"}),f(!0)};return c(Qe,{isLoading:l,header:t(xn,{title:`Variants (${I.length})`,actions:t(O,{children:t(ge,{onClick:ta,"data-testid":"ADD_VARIANT_BUTTON",permission:ke,projectId:n,children:"New variant"})})}),children:[c(he,{severity:"info",sx:{marginBottom:"1rem"},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",{style:{fontWeight:"bold"},children:"getVariant()"})," method in the Client SDK."]}),c(Qa,{...te(),children:[t(Rt,{headerGroups:C}),t(kt,{...B(),children:I.map(P=>(N(P),t(Ft,{hover:!0,...P.getRowProps(),style:{height:"75px"},children:P.cells.map(L=>t(Za,{...L.getCellProps(),padding:"none",children:L.render("Cell")}))})))})]}),t(E,{condition:I.length===0,show:t(An,{children:"No variants available. Get started by adding one."})}),t("br",{}),t("div",{children:t(E,{condition:D,show:W()})}),t(Zs,{showDialog:S,closeDialog:z,save:async P=>d?Bt(P):Xn(P),editing:d,validateName:Qn,validateWeight:Zn,editVariant:T,title:d?"Edit variant":"Add variant"}),ea]})},ri=p("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"}}})),oi=p(Rn)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),si=p("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),ii=p(Gn)(()=>({width:"100%"})),li=p(Et)(()=>({width:"100%"})),ci=({overrides:e,overridesDispatch:n})=>{const{context:a}=Ee(),r=a.map(({name:s})=>({key:s,label:s})),o=s=>i=>{n({type:"UPDATE_VALUES_AT",payload:[s,i]})},l=s=>(i,d)=>{i==null||i.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[s,d||[]]})};return t(O,{children:e.map((s,i)=>{var h;const d=a.find(({name:b})=>b===s.contextName),u=((h=d==null?void 0:d.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=s.values.filter(b=>u.includes(b));return c(ri,{children:[t(oi,{id:"override-context-name",name:"contextName",label:"Context Field",value:s.contextName,options:r,onChange:b=>n({type:"UPDATE_TYPE_AT",payload:[i,b.target.value]})}),c(si,{children:[t(E,{condition:Boolean(u&&u.length>0),show:t(bn,{multiple:!0,id:`override-select-${i}`,isOptionEqualToValue:(b,y)=>b===y,options:u,onChange:l(i),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(li,{...b,variant:"outlined",label:"Legal values"})}),elseShow:t(ii,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:s.values,updateValues:o(i)})}),t(le,{title:"Remove",arrow:!0,children:t(Ne,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:i})},children:t(Ve,{})})})]})]},`override=${i}`)})})},di=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((s,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((s,i)=>i===a?{...s,values:r}:s);case"UPDATE_TYPE_AT":const[o,l]=n.payload;return e.map((s,i)=>i===o?{...s,contextName:l}:s)}},ui=(e=[])=>m.useReducer(di,e);var oe=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(oe||{});const pi=p("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})),gi=p(Ne)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Yn=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),en=p(Yn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),hi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),mi=p(vn)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),tn=p(Ce)(()=>({width:"100%"})),yi=p("div")(({theme:e})=>({marginLeft:e.spacing(3)})),fi=p(Ce)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Si=p("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),Kn=p("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%"}}})),bi=p(Kn)({alignItems:"end",justifyContent:"space-between"}),vi=p(Rn)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),Ci=p(me)(({theme:e})=>({width:e.spacing(20),maxWidth:"100%"})),wi=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Ti={type:"string",value:""},xi=({variant:e,variants:n,updateVariant:a,removeVariant:r,apiPayload:o})=>{const[l,s]=m.useState(e.name),[i,d]=m.useState(e.weightType===oe.FIX),[u,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||Ti),[y,T]=ui(e.overrides||[]),{context:w}=Ee(),[S,f]=m.useState({}),v=C=>{f(I=>({...I,[C]:void 0}))},x=(C,I)=>{f(N=>({...N,[C]:I}))};m.useEffect(()=>{var C;v("percentage"),(C=o.error)!=null&&C.includes("%")&&x("percentage","Total weight must equal 100%")},[o.error]);const A=!e.new,$=n.filter(({id:C,weightType:I})=>C!==e.id&&I===oe.VARIABLE).length>0,F=C=>{const I=C.weightType===oe.VARIABLE,N=n.some(R=>R.weightType===oe.FIX),V=n.filter(R=>R.weightType===oe.VARIABLE).length==1;return N&&V&&I},M=C=>{v("name"),ee(C,e.id)||x("name","A variant with that name already exists for this environment."),s(C)},D=C=>{(C===""||te(C))&&g(C)},Y=C=>{B(C)||x("payload","Invalid JSON.")},q=()=>{w.length>0&&T({type:"ADD",payload:{contextName:w[0].name,values:[]}})},G=C=>Boolean(C.length),ee=(C,I)=>A||!n.some(N=>N.name===C&&N.id!==I),te=C=>{if(!i)return!0;if(C===""||C.match(/\.[0-9]{2,}$/))return!1;const I=Number(C);return I>=0&&I<=100},B=C=>{try{return C.type==="json"&&JSON.parse(C.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:l,weight:Number(i?u:100)*10,weightType:i?oe.FIX:oe.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:G(l)&&ee(l,e.id)&&te(u)&&B(h)&&!o.error})},[l,i,u,h,y]),m.useEffect(()=>{i||g(String(e.weight/10))},[e.weight]),c(pi,{children:[t(gi,{onClick:()=>r(e.id),disabled:F(e),children:t(Ve,{})}),c(bi,{children:[c(Si,{children:[t(Yn,{children:"Variant name"}),t(hi,{children:"This will be used to identify the variant in your code"}),t(tn,{autoFocus:!0,label:"Variant name",error:Boolean(S.name),errorText:S.name,value:l,onChange:C=>M(C.target.value),disabled:A,required:!0})]}),t(E,{condition:$,show:c(yi,{children:[t(mi,{label:"Custom percentage",control:t(er,{checked:i,onChange:C=>d(C.target.checked)})}),t(fi,{type:"number",label:"Variant weight",error:Boolean(S.percentage),errorText:S.percentage,value:u,onChange:C=>D(C.target.value),required:i,disabled:!i,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(Cn,{position:"end",children:"%"})}})]})})]}),c(en,{children:["Payload",t(ve,{tooltip:"Passed along with the the variant object."})]}),c(Kn,{children:[t(vi,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:wi,onChange:C=>{v("payload"),b(I=>({...I,type:C.target.value}))}}),t(tn,{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=>{v("payload"),b(I=>({...I,value:C.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>Y(h),error:Boolean(S.payload),errorText:S.payload})]}),c(en,{children:["Overrides",t(ve,{tooltip:"Here you can specify which users should get this variant."})]}),t(ci,{overrides:y,overridesDispatch:T}),t(Ci,{onClick:q,variant:"outlined",color:"primary",children:"Add override"})]})},Ai=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-1.5),marginBottom:e.spacing(4)})),Ei=p(kn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Ii=p("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})),Ri=p("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ki=p(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Fi=p(he)(({theme:e})=>({marginTop:e.spacing(4)})),Pi=p("div")(({theme:e})=>({display:"flex",flexDirection:"column-reverse"})),Bi=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),nn=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),$i=p(Ae)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Vi=p("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Di=p(me)(({theme:e})=>({marginLeft:e.spacing(3)})),Oi=({environment:e,open:n,setOpen:a,getApiPayload:r,getCrPayload:o,onConfirm:l})=>{var V;const s=k("projectId"),i=k("featureId"),{uiConfig:d}=Te(),{context:u}=Ee(),{isChangeRequestConfigured:g}=pe(s),{data:h}=Oe(s),{changeRequestInReviewOrApproved:b,alert:y}=nr(h),T=(e==null?void 0:e.variants)||[],[w,S]=m.useState([]);m.useEffect(()=>{S(T.length?T.map(R=>({...R,isValid:!0,new:!1,id:rt()})):[{name:"",weightType:oe.VARIABLE,weight:0,overrides:[],stickiness:(w==null?void 0:w.length)>0?w[0].stickiness:"default",new:!0,isValid:!1,id:rt()}])},[n]);const f=(R,z)=>{S(W=>Lt(W.map(re=>re.id===z?R:re),1e3))},v=w.map(({new:R,isValid:z,id:W,...re})=>re),x=r(T,v),A=o(v),$=async R=>{R.preventDefault(),l(v)},F=()=>q?`curl --location --request POST '${d.unleashUrl}/api/admin/projects/${s}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
2
|
+
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
|
+
--header 'Content-Type: application/json' \\
|
|
4
|
+
--data-raw '${JSON.stringify(A,void 0,2)}'`:`curl --location --request PATCH '${d.unleashUrl}/api/admin/projects/${s}/features/${i}/environments/${e==null?void 0:e.name}/variants' \\
|
|
5
|
+
--header 'Authorization: INSERT_API_KEY' \\
|
|
6
|
+
--header 'Content-Type: application/json' \\
|
|
7
|
+
--data-raw '${JSON.stringify(x.patch,void 0,2)}'`,M=w.every(({isValid:R})=>R),D=b((e==null?void 0:e.name)||""),Y=D?"Add to existing change request":"Add change to draft",q=g((e==null?void 0:e.name)||"")&&d.flags.crOnVariants,G=((V=v[0])==null?void 0:V.stickiness)||"default",ee=m.useMemo(()=>["default",...u.filter(R=>R.stickiness).map(R=>R.name)],[u]),te=ee.map(R=>({key:R,label:R}));ee.includes(G)||te.push({key:G,label:G});const B=async R=>{S(z=>z.map(W=>({...W,stickiness:R})))},C=R=>{B(R).catch(console.warn)},[I,N]=m.useState();return m.useEffect(()=>{N(void 0),x.error&&N(x.error)},[x.error]),t(ht,{open:n,onClose:()=>{a(!1)},label:"",children:c(tr,{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:F,loading:!n,children:[c(Ai,{children:[c("div",{children:[t(Ei,{deprecated:!(e!=null&&e.enabled)}),t(Ii,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ge,{onClick:()=>S(R=>[...R,{name:"",weightType:oe.VARIABLE,weight:0,overrides:[],stickiness:(R==null?void 0:R.length)>0?R[0].stickiness:"default",new:!0,isValid:!1,id:rt()}]),variant:"outlined",permission:Re,projectId:s,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(Ri,{onSubmit:$,children:[t(E,{condition:D,show:y,elseShow:t(E,{condition:Boolean(q),show:c(ki,{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(Pi,{children:w.map(R=>t(xi,{variant:R,variants:w,updateVariant:z=>f(z,R.id),removeVariant:()=>S(z=>Lt(z.filter(W=>W.id!==R.id),1e3)),projectId:s,apiPayload:x},R.id))}),t(E,{condition:w.length>0,show:c(O,{children:[t(Bi,{children:t("p",{children:"Stickiness"})}),c(nn,{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($i,{options:te,value:G,onChange:C})})]}),elseShow:t(nn,{children:"This environment has no variants. Get started by adding a variant."})}),c(Fi,{severity:"error",hidden:!Boolean(I),children:[t("strong",{children:"Error: "}),I]}),c(Vi,{children:[t(me,{type:"submit",variant:"contained",color:"primary",disabled:!M,children:q?Y:"Save variants"}),t(Di,{onClick:()=>{a(!1)},children:"Cancel"})]})]})]})})},Li=p(H)(({theme:e})=>({fontSize:e.fontSizes.smallerBody,whiteSpace:"pre-wrap"})),Ni=({value:e})=>{const{searchQuery:n}=Fn();return e?e.type==="string"&&e.value.length<20?t(Z,{children:t(yt,{search:n,children:e.value})}):t(Z,{children:t(Pn,{tooltip:t(O,{children:t(Li,{children:t(yt,{search:n,children:e.value})})}),highlighted:n.length>0&&e.value.toLowerCase().includes(n.toLowerCase()),children:e.type})}):t(Z,{})},Mi=p(H)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),ji=({value:e})=>{const{searchQuery:n}=Fn();if(!e||e.length===0)return t(Z,{});const a=r=>`${r.contextName}:${r.values.join()}`;return t(Z,{children:t(Pn,{tooltip:t(O,{children:e.map((r,o)=>t(Mi,{children:t(yt,{search:n,children:a(r)})},r.contextName+o))}),highlighted:n.length>0&&(e==null?void 0:e.map(a).join(`
|
|
8
|
+
`).toLowerCase().includes(n.toLowerCase())),children:e.length===1?"1 override":`${e.length} overrides`})})},_i=p("div")(({theme:e})=>({margin:e.spacing(3,0)})),zi=({environment:e,searchValue:n})=>{const a=k("projectId"),r=Ye(),o=ue(r.breakpoints.down("md")),l=ue(r.breakpoints.down("lg")),s=e.variants??[],i=m.useMemo(()=>[{Header:"Name",accessor:"name",Cell:ar,sortType:"alphanumeric",minWidth:350,searchable:!0},{Header:"Payload",accessor:"payload",Cell:Ni,disableSortBy:!0,searchable:!0,filterParsing:f=>f==null?void 0:f.value},{Header:"Overrides",accessor:"overrides",Cell:ji,disableSortBy:!0,searchable:!0,filterParsing:f=>(f==null?void 0:f.map(({contextName:v,values:x})=>`${v}:${x.join()}`).join(`
|
|
9
|
+
`))||""},{Header:"Weight",accessor:"weight",Cell:({row:{original:{name:f,weight:v}}})=>c(Z,{"data-testid":`VARIANT_WEIGHT_${f}`,children:[wn(v)," %"]}),sortType:"number"},{Header:"Type",accessor:f=>f.weightType==="fix"?"Fixed":"Variable",Cell:Z,sortType:"alphanumeric"}],[a,s,e]),d=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{data:u,getSearchText:g}=rr(i,n,s),{getTableProps:h,getTableBodyProps:b,headerGroups:y,rows:T,prepareRow:w,setHiddenColumns:S}=de.useTable({columns:i,data:u,initialState:d,sortTypes:Tn,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},de.useSortBy);return It([{condition:o,columns:["payload","overrides"]},{condition:l,columns:["weightType"]}],S,i),c(_i,{children:[t(or,{value:g(n),children:c(Bn,{...h(),children:[t(Rt,{headerGroups:y}),t(kt,{...b(),children:T.map(f=>(w(f),t(Ft,{hover:!0,...f.getRowProps(),children:f.cells.map(v=>t($n,{...v.getCellProps(),children:v.render("Cell")}))})))})]})}),t(E,{condition:T.length===0,show:t(E,{condition:(n==null?void 0:n.length)>0,show:c(An,{children:["No variants found matching “",n,"”"]})})})]})},Wi=p("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.dividerAlternative}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Hi=p("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Ui=p(kn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),qi=p("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})),Gi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Yi=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Ki=({environment:e,searchValue:n,children:a})=>{var l;const r=e.variants??[],o=((l=r[0])==null?void 0:l.stickiness)||"default";return c(Wi,{children:[c(Hi,{children:[c("div",{children:[t(Ui,{deprecated:!e.enabled}),t(qi,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:r.length>0,show:c(O,{children:[t(zi,{environment:e,searchValue:n}),t(E,{condition:r.length>1,show:c(O,{children:[c(Yi,{children:[t("p",{children:"Stickiness:"}),t(gt,{children:o})]}),c(Gi,{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"})]})]})})]})})]})},Ji=p(wt)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Xi=({environment:e,permission:n,projectId:a,environmentId:r,onCopyVariantsFrom:o,otherEnvsWithVariants:l})=>{const[s,i]=m.useState(null),d=Boolean(s),u=e.variants??[];return t(E,{condition:l.length>0&&u.length===0,show:c(O,{children:[t(ge,{onClick:g=>{i(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:r,children:"Copy variants from"}),t(Ke,{anchorEl:s,open:d,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:l.map(g=>t(Je,{onClick:()=>o(g,e),children:t(Ji,{children:`Copy from ${g.name}`})},g.name))})]})})},Qi=({permission:e,projectId:n,environment:a,checked:r,onClick:o,...l})=>{const s=sr(e,n,a);return c(Je,{disabled:!s,onClick:o,...l,children:[t(ir,{checked:r}),a]})},Zi=p(Ke)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),el=p("div")(({theme:e})=>({margin:e.spacing(1,2)})),tl=p(me)(({theme:e})=>({marginTop:e.spacing(2)})),nl=({current:e,environments:n,permission:a,projectId:r,onSubmit:o})=>{var w;const[l,s]=m.useState(null),i=Boolean(l),[d,u]=m.useState([]),g=S=>{u(f=>[...f,S])},h=S=>{u(f=>f.filter(({name:v})=>v!==S.name))},b=S=>{d.includes(S)?h(S):g(S)},y=()=>{u([]),s(null)},T=((w=n.find(S=>S.name===e))==null?void 0:w.variants)??[];return t(E,{condition:T.length>0&&n.length>1,show:c(O,{children:[t(me,{onClick:S=>{s(S.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,variant:"outlined",children:"Push to environment"}),c(Zi,{anchorEl:l,open:i,onClose:()=>s(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(S=>S.name!==e).map(S=>t(Qi,{projectId:r,permission:a,environment:S.name,checked:d.includes(S),onClick:()=>b(S)},S.name)),c(el,{children:[t(We,{}),c(tl,{variant:"outlined",onClick:()=>{o(d),y()},disabled:d.length===0,children:["Push to selected (",d.length,")"]})]})]})]})})},al=p(he)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),rl=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),ol=()=>{const{uiConfig:e}=Te(),{setToastData:n,setToastApiError:a}=K(),r=Ye(),o=ue(r.breakpoints.down("md")),l=k("projectId"),s=k("featureId"),{feature:i,refetchFeature:d,loading:u}=_(l,s),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=ce(),{refetch:b}=Oe(l),{addChange:y}=Ct(),{isChangeRequestConfigured:T}=pe(l),[w,S]=m.useState(""),[f,v]=m.useState(),[x,A]=m.useState(!1),$=m.useMemo(()=>{var B;return((B=i==null?void 0:i.environments)==null?void 0:B.map(C=>({...C,crEnabled:e.flags.crOnVariants&&T(C.name)})))||[]},[i.environments,e.flags.crOnVariants]),F=(B,C)=>In(B,C),M=(B,C)=>{try{const I=En(C,1e3);return{patch:F(B,I)}}catch(I){return{patch:[],error:j(I)}}},D=B=>({feature:s,action:"patchVariant",payload:{variants:B}}),Y=async(B,C)=>{if(B.crEnabled)await y(l,B.name,D(C)),b();else{const I=B.variants??[],{patch:N,error:V}=M(I,C);if(N.length===0)return;if(V){n({type:"error",title:V});return}await g(l,s,B.name,N)}d()},q=async(B,C)=>{try{const I=C.filter(({crEnabled:W})=>W),N=C.filter(({crEnabled:W})=>!W);I.length&&await Promise.all(I.map(W=>y(l,W.name,D(B)))),N.length&&await h(l,s,B,N.map(({name:W})=>W)),b(),d();const V=N.length?`Variants pushed to ${N.length===1?N[0].name:`${N.length} environments`}`:"",R=I.length?`Variants push added to ${I.length===1?`${I[0].name} draft`:`${I.length} drafts`}`:"",z=`${V}${V&&R?". ":""}${R}`;n({title:z,type:"success"})}catch(I){a(j(I))}},G=B=>{v(B),A(!0)},ee=async B=>{if(f)try{await Y(f,B),A(!1),n({title:f.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(C){a(j(C))}},te=async(B,C)=>{try{const I=B.variants??[];await Y(C,I),n({title:C.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(I){a(j(I))}};return c(Qe,{isLoading:u,header:t(xn,{title:"Variants",actions:t(E,{condition:!o,show:t(O,{children:t(Nt,{initialValue:w,onChange:S})})}),children:t(E,{condition:o,show:t(Nt,{initialValue:w,onChange:S})})}),children:[c(al,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(B=>{var I;const C=$.filter(({name:N,variants:V})=>N!==B.name&&(V==null?void 0:V.length));return t(Ki,{environment:B,searchValue:w,children:c(rl,{children:[t(nl,{current:B.name,environments:$,permission:Re,projectId:l,onSubmit:N=>q(B.variants??[],N)}),t(Xi,{environment:B,permission:Re,projectId:l,environmentId:B.name,onCopyVariantsFrom:te,otherEnvsWithVariants:C}),t(E,{condition:Boolean((I=B.variants)==null?void 0:I.length),show:t(ne,{onClick:()=>G(B),permission:Re,projectId:l,environmentId:B.name,children:t(Se,{})}),elseShow:t(ge,{onClick:()=>G(B),variant:"outlined",permission:Re,projectId:l,environmentId:B.name,children:"Add variant"})})]})},B.name)}),t(Oi,{environment:f,open:x,setOpen:A,getApiPayload:M,getCrPayload:D,onConfirm:ee})]})},sl=()=>{At("Variants");const{uiConfig:e}=Te();return e.flags.variantsPerEnvironment?t(ol,{}):t(ai,{})},il=Pe("api/admin/client-metrics/features"),Jn=(e,n)=>{const a=Pe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:o}=vt(a,()=>ll(a)),l=m.useCallback(()=>{bt(il).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!o&&!r,refetchFeatureMetrics:l,error:o}},ll=e=>fetch(e).then(Ge("Features")).then(n=>n.json()).then(),Fe=48,cl=({hoursBack:e,setHoursBack:n})=>{const a=r=>{n(dl(r))};return t(Ae,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:ul,value:String(e),onChange:a,fullWidth:!0})},dl=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Fe}},ul=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Fe}`,label:`Last ${Fe} hours`}],pl=({metrics:e,tableSectionId:n})=>{const a=ue(He.breakpoints.down("md")),r=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:l,headerGroups:s,rows:i,prepareRow:d,setHiddenColumns:u}=de.useTable({initialState:r,columns:an,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Z}},de.useGlobalFilter,de.useSortBy);return It([{condition:a,columns:["appName","environment"]}],u,an),e.length===0?null:c(Bn,{...o(),rowHeight:"standard",id:n,children:[t(Rt,{headerGroups:s}),t(kt,{...l(),children:i.map(g=>(d(g),t(Ft,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t($n,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},an=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(lr,{icon:t(jr,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(cr,{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"}],gl=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((o,l)=>o+l.yes,0),[e]),r=m.useMemo(()=>e.reduce((o,l)=>o+l.no,0),[e]);return t(Hn,{...n,totalYes:a,totalNo:r})},hl=({metrics:e,hoursBack:n})=>{const a=Mt(),r=Mt();return e.length===0?c(Q,{mt:6,children:[t(H,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(H,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):c(m.Suspense,{fallback:null,children:[t(Q,{borderTop:1,pt:2,mt:3,borderColor:He.palette.grey[200],children:t(ml,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Q,{mt:4,children:t(gl,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:r})}),t(Q,{mt:4,children:t(pl,{metrics:e,tableSectionId:r})})]})},ml=dr.lazy(()=>import("./FeatureMetricsChart-d491608e.js")),St=e=>{const{search:n}=window.location,a=xe(),r=m.useMemo(()=>new URLSearchParams(n),[n]),o=m.useCallback(l=>{const s=new URLSearchParams(n);s.set(e,l),a({search:s.toString()},{replace:!0})},[e,n,a]);return[r.get(e)||void 0,o]},yl=e=>{const[n,a]=St(e),r=m.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,r]},fl=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Sl=p("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),bl=p("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText}})),rn=({title:e,values:n,value:a,setValue:r})=>{const o=s=>()=>{n.has(s)&&r(s)},l=m.useMemo(()=>Array.from(n).sort((s,i)=>s.localeCompare(i)),[n]);return c("div",{children:[t(fl,{children:e}),t(Sl,{children:l.map(s=>t(bl,{children:t(Be,{label:s,onClick:o(s),"aria-pressed":s===a,sx:ur})},s))})]})},vl=p("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),Cl=()=>{const e=k("projectId"),n=k("featureId"),a=wl(e,n),r=Tl(n);At("Metrics");const[o=Fe,l]=yl("hoursBack"),{featureMetrics:s}=Jn(n,o),[i,d]=m.useState(s);m.useEffect(()=>{s&&d(s)},[s]);const u=Array.from(a)[0],g=Array.from(r)[0],[h=u,b]=St("environment"),[y=g,T]=St("application"),w=m.useMemo(()=>i==null?void 0:i.filter(S=>S.environment===h).filter(S=>S.appName===y),[i,h,y]);return w?c(Qe,{children:[c(U,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(U,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(rn,{title:"Environments",values:a,value:h,setValue:b})})}),t(U,{item:!0,xs:12,md:5,children:t(E,{condition:r.size>0,show:t(rn,{title:"Applications",values:r,value:y,setValue:T})})}),t(U,{item:!0,xs:12,md:2,children:t(vl,{children:t(cl,{hoursBack:o,setHoursBack:l})})})]}),t(hl,{metrics:w,hoursBack:o})]}):null},wl=(e,n)=>{const{feature:a}=_(e,n),r=a.environments.map(o=>o.name);return new Set(r)},Tl=e=>{const{featureMetrics:n=[]}=Jn(e,Fe),a=n.map(r=>r.appName);return new Set(a)},xl=(e,n)=>{const a=new Set(e),r=new Set(n);return a.size!==r.size?!1:[...a].every(o=>r.has(o))},on=p("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),sn=p(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Al=p(Tt)({padding:0}),El=({projectId:e,open:n,onClose:a,onClick:r,feature:o,changeRequests:l})=>{const s=k("projectId"),{project:i}=Vn(e),d=m.useMemo(()=>xl(o.environments.map(g=>g.name),i.environments),[o,i]),u=l?l.length>0:!1;return t(E,{condition:d&&!u,show:t(ie,{open:n,onClose:a,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(on,{children:[t(sn,{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:c(on,{children:[t(sn,{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:u,show:c(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(Al,{children:l==null?void 0:l.map(g=>t(ze,{children:c(se,{to:`/projects/${s}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})})]})})})},Il=e=>fetch(e).then(Ge("ChangeRequest")).then(n=>n.json()),Rl=(e,n)=>{const{data:a,error:r,mutate:o}=pr([],Pe(`api/admin/projects/${e}/change-requests/pending/${n}`),Il);return{changeRequests:a,loading:!r&&!a,refetch:o,error:r}},kl=()=>{const{hasAccess:e}=m.useContext($e),n=k("projectId"),a=k("featureId"),{feature:r,refetchFeature:o}=_(n,a),[l,s]=m.useState(!1),{changeFeatureProject:i}=ce(),{setToastData:d,setToastApiError:u}=K(),[g,h]=m.useState(n),{projects:b}=gr(),y=xe(),{changeRequests:T}=Rl(n,a),w=async()=>{try{g&&(await i(n,a,g),o(),d({title:"Project changed",type:"success"}),s(!1),y(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(f){u(j(f))}},S=m.useMemo(()=>b.map(f=>f.id).filter(f=>e(jt,f)),[b,e]);return S.length===0?null:c(O,{children:[t(hr,{value:g,onChange:h,label:"Project",filter:f=>S.includes(f),enabled:!0}),t(ge,{permission:jt,onClick:()=>s(!0),disabled:g===n,projectId:n,children:"Save"}),t(El,{changeRequests:T,projectId:g,open:l,feature:r,onClose:()=>s(!1),onClick:w})]})},Fl=p("div")({display:"flex",alignItems:"center"}),Pl=p(H)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),Bl=({projectId:e,featureId:n})=>{var l;const{feature:a}=_(e,n),r=xe();return c(O,{children:[c(Fl,{children:[t(Pl,{children:"Feature information"}),t(ne,{permission:fe,projectId:e,"data-loading":!0,onClick:()=>{r(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(Se,{})})]}),c(H,{children:["Name: ",t("strong",{children:a.name})]}),c(H,{children:["Description:"," ",t("strong",{children:(l=a.description)!=null&&l.length?a.description:"no description"})]}),c(H,{children:["Type: ",t("strong",{children:a.type})]}),c(H,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},je="metadata",pt="project",$l=p("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Vl=p("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),Dl=()=>{const e=k("projectId"),n=k("featureId"),[a,r]=m.useState(je),{uiConfig:o}=Te();return t(Qe,{header:"Settings",sx:{padding:0},children:c(Q,{sx:{display:"flex"},children:[t($l,{children:c(Tt,{children:[t(ze,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(je),selected:a===je,children:"Metadata"},0),t(ze,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(pt),selected:a===pt,hidden:!o.flags.P,children:"Project"},1)]})}),c(Vl,{children:[t(E,{condition:a===je,show:t(Bl,{projectId:e,featureId:n})}),t(E,{condition:a===pt&&o.flags.P,show:t(kl,{})})]})]})})},Ol=p(Be)(({theme:e})=>({background:"transparent",border:`1px solid ${e.palette.primary.main}`,color:e.palette.primary.main})),Ll=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Ol,{color:"primary",variant:"outlined",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",label:e?"Stale":"Active"})}),ln=p("strong")({wordBreak:"break-all"}),Nl=()=>{const e=k("projectId"),n=k("featureId"),{archivedFeatures:a}=mr(),r=yr(e,{name:n});return a?a.some(l=>l.name===n)?c("p",{children:["The feature ",t(ln,{children:n})," has been archived. You can find it on the"," ",t(se,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(ln,{children:n})," does not exist. Would you like to"," ",t(se,{to:r,children:"create it"}),"?"]}):null},Ml=p("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),jl=p("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),_l=p("div")({display:"flex",alignItems:"center"}),zl=p("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Wl=p("div")({flexShrink:0,display:"flex"}),Hl=p("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.tertiary.light,height:"1px"})),Ul=p("div")(({theme:e})=>({padding:e.spacing(0,4)})),ql=p(fr)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Ql=()=>{const e=k("projectId"),n=k("featureId"),{refetch:a}=Vn(e),{favorite:r,unfavorite:o}=Sr(),{refetchFeature:l}=_(e,n),[s,i]=m.useState(!1),[d,u]=m.useState(!1),[g,h]=m.useState(!1),b=ue(`(max-width:${500}px)`),{feature:y,loading:T,error:w,status:S}=_(e,n),f=xe(),{pathname:v}=br(),x=vr(T),A=`/projects/${e}/features/${n}`,$=[{title:"Overview",path:`${A}`,name:"overview"},{title:"Metrics",path:`${A}/metrics`,name:"Metrics"},{title:"Variants",path:`${A}/variants`,name:"Variants"},{title:"Settings",path:`${A}/settings`,name:"Settings"},{title:"Event log",path:`${A}/logs`,name:"Event log"}],F=$.find(D=>D.path===v)??$[0],M=async()=>{y!=null&&y.favorite?await o(e,y.name):await r(e,y.name),l()};return S===404?t(Nl,{}):w!==void 0?t("div",{ref:x}):c("div",{ref:x,children:[c(Ml,{children:[c(jl,{children:[c(_l,{children:[t(Cr,{onClick:M,isFavorite:y==null?void 0:y.favorite}),c(zl,{"data-loading":!0,children:[y.name," "]}),t(E,{condition:!b,show:t(Ll,{stale:y==null?void 0:y.stale})})]}),c(Wl,{children:[t(ne,{permission:wr,projectId:e,"data-loading":!0,component:se,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Tr,{})}),t(ne,{permission:xr,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(Mr,{})}),t(ne,{onClick:()=>h(!0),permission:fe,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(zr,{})}),t(ne,{onClick:()=>i(!0),permission:fe,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(dn,{})})]})]}),t(Hl,{}),t(Ul,{children:t(Ar,{value:F.path,indicatorColor:"primary",textColor:"primary",children:$.map(D=>t(ql,{label:D.title,value:D.path,onClick:()=>f(D.path)},D.title))})})]}),c(fn,{children:[t(ye,{path:"metrics",element:t(Cl,{})}),t(ye,{path:"logs",element:t(Hr,{})}),t(ye,{path:"variants",element:t(sl,{})}),t(ye,{path:"settings",element:t(Dl,{})}),t(ye,{path:"*",element:t(Hs,{})})]}),t(kr,{isOpen:d,onConfirm:()=>{a(),f(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureId:n}),t(Fr,{isStale:y.stale,isOpen:g,onClose:()=>{h(!1),l()},featureId:n,projectId:e}),t(qn,{open:s,setOpen:i})]})};export{Ql as default};
|