unleash-server 4.20.1-beta.0 → 4.20.1

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