unleash-server 5.1.0-beta.39 → 5.1.0-beta.40

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