unleash-server 4.20.1 → 4.20.2-beta.0

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