unleash-server 4.22.0-beta.97 → 4.22.0-beta.99

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