unleash-server 5.1.0-beta.2 → 5.1.0-beta.4

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 (19) hide show
  1. package/frontend/build/index.html +1 -1
  2. package/frontend/build/static/{CreateProject-ce995a9d.js → CreateProject-b3b2d069.js} +1 -1
  3. package/frontend/build/static/{Error-fcc2de03.js → Error-e6d99a4a.js} +1 -1
  4. package/frontend/build/static/{FeatureArchiveDialog-4bbeeb8f.js → FeatureArchiveDialog-38d9b74d.js} +1 -1
  5. package/frontend/build/static/{FeatureMetricsChart-5fc52117.js → FeatureMetricsChart-a404022d.js} +1 -1
  6. package/frontend/build/static/{FeatureViewLazyExport-b3f2e867.js → FeatureViewLazyExport-5705cfd5.js} +2 -2
  7. package/frontend/build/static/{LazyAdminExport-cc149371.js → LazyAdminExport-32e30e1a.js} +2 -2
  8. package/frontend/build/static/{LazyProjectExport-db27dd13.js → LazyProjectExport-443ea35d.js} +1 -1
  9. package/frontend/build/static/{NetworkOverview-372ad8b2.js → NetworkOverview-7e75302f.js} +1 -1
  10. package/frontend/build/static/{NetworkTraffic-dfe62619.js → NetworkTraffic-49f561ef.js} +1 -1
  11. package/frontend/build/static/{Playground-8fbb7d94.js → Playground-8f360c73.js} +1 -1
  12. package/frontend/build/static/{StrategyItemContainer-e26123be.js → StrategyItemContainer-7abceb2f.js} +1 -1
  13. package/frontend/build/static/{chartjs-adapter-date-fns.esm-16be4b37.js → chartjs-adapter-date-fns.esm-f8cb8a7c.js} +1 -1
  14. package/frontend/build/static/{index-562cdc1c.js → index-0ef02266.js} +1 -1
  15. package/frontend/build/static/{index-36e7b066.js → index-40d672e9.js} +68 -68
  16. package/frontend/build/static/{index-34846b98.js → index-f9373b73.js} +1 -1
  17. package/frontend/build/static/{unknownify-b3fbf6dd.js → unknownify-a3f08894.js} +1 -1
  18. package/frontend/build/static/{useProjectRole-af57e69a.js → useProjectRole-10dc2275.js} +1 -1
  19. package/package.json +1 -1
@@ -16,7 +16,7 @@
16
16
  href="https://fonts.googleapis.com/css2?family=Sen:wght@400;700;800&display=swap"
17
17
  rel="stylesheet"
18
18
  />
19
- <script type="module" crossorigin src="/static/index-36e7b066.js"></script>
19
+ <script type="module" crossorigin src="/static/index-40d672e9.js"></script>
20
20
  <link rel="stylesheet" href="/static/index-870c8122.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-36e7b066.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-40d672e9.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-36e7b066.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-40d672e9.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 z,j as s,aF as k,a_ as F,f as T,aX as w,C as S,A as ae,T as A,c1 as se,f2 as $,r as f,f3 as ne,f4 as re,aY as oe,aZ as U,a2 as P,H as ie,ao as j,aG as N,aS as ce,ap as le,f5 as ue,f6 as ge,as as de,b4 as he,f7 as pe,f8 as fe,f9 as ye,fa as me,b6 as I,a$ as Te,a4 as R,fb as ve,s as O,aW as Ee,fc as be,fd as Se,F as Y,dU as Ae,dV as Ce,dW as Re,ad as W,ac as J,bM as we,c4 as Pe,d2 as xe,w as _e,fe as ke,d1 as Fe,u as Oe,Z as qe,bI as De,aR as Be,aP as Le,aQ as $e,bE as H,ar as Ne}from"./index-36e7b066.js";const Ze=z(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"),Xe=z(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"),et=({isOpen:e,onConfirm:t,onClose:n,showBanner:o,environment:a,messageComponent:r})=>{const c=k("projectId"),{data:h}=F(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(S,{condition:d,show:u}),s(S,{condition:Boolean(o),show:T(ae,{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(A,{variant:"body2",color:"text.secondary",children:"Your suggestion:"}),r]})},tt="UPDATE_FEATURE_STRATEGY",at="UPDATE_PROJECT",st="READ_PROJECT_API_TOKEN",nt="CREATE_PROJECT_API_TOKEN",rt="DELETE_PROJECT_API_TOKEN",Ve=(e,t)=>{const n={};return t.parameters.forEach(o=>{n[o.name]=ze(e,o)}),{name:t.name,constraints:[],parameters:n}},ze=(e,t)=>t.name==="rollout"||t.name==="percentage"||t.type==="percentage"?"50":t.name==="stickiness"?"":t.name==="groupId"?e:t.type==="boolean"?"false":"",ot=()=>{const e=k("projectId"),t=k("featureId"),n=$("environmentId"),o=$("strategyName"),[a,r]=f.useState({}),[c,h]=f.useState([]),{strategyDefinition:l}=ne(o),u=re(),{addStrategyToFeature:d,loading:y}=oe(),{addChange:i}=U(),{setToastData:g,setToastApiError:v}=P(),{uiConfig:p}=ie(),{unleashUrl:m}=p,E=j(),{feature:b,refetchFeature:D}=N(e,t),B=f.useRef(b),{isChangeRequestConfigured:L}=ce(e),{refetch:M}=F(e),{trackEvent:G}=le(),{data:x,staleDataNotification:Q,forceRefreshCache:Z}=ue({unleashGetter:N,params:[e,t],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},b,{afterSubmitAction:D},ve);f.useEffect(()=>{B.current.name===""&&b.name&&(Z(b),B.current=b)},[b.name]),f.useEffect(()=>{l&&r(Ve(t,l))},[t,l]);const X=async C=>{await d(e,t,n,C),g({title:"Strategy created",type:"success",confetti:!0})},ee=async C=>{await i(e,n,{action:"addStrategy",feature:t,payload:C}),g({title:"Strategy added to draft",type:"success",confetti:!0}),M()},_=ge(a,c),te=async()=>{G("strategyTitle",{props:{hasTitle:Boolean(a.title),on:"create"}});try{L(n)?await ee(_):await X(_),D(),E(Te(e,t))}catch(C){v(R(C))}};return!x||!x.project?null:T(de,{modal:!0,title:he(o),description:pe,documentationLink:fe,documentationLinkLabel:ye,formatApiCode:()=>je(e,t,n,_,m),children:[s(me,{projectId:e,feature:x,strategy:a,setStrategy:r,segments:c,setSegments:h,environmentId:n,onSubmit:te,loading:y,permission:I,errors:u,isChangeRequest:L(n)}),Q]})},Ue=(e,t,n,o)=>{const a=new URLSearchParams({environmentId:n,strategyName:o});return`/projects/${e}/features/${t}/strategies/create?${a}`},je=(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 z,j as s,aF as k,a_ as F,f as T,aX as w,C as S,A as ae,T as A,c1 as se,f2 as $,r as f,f3 as ne,f4 as re,aY as oe,aZ as U,a2 as P,H as ie,ao as j,aG as N,aS as ce,ap as le,f5 as ue,f6 as ge,as as de,b4 as he,f7 as pe,f8 as fe,f9 as ye,fa as me,b6 as I,a$ as Te,a4 as R,fb as ve,s as O,aW as Ee,fc as be,fd as Se,F as Y,dU as Ae,dV as Ce,dW as Re,ad as W,ac as J,bM as we,c4 as Pe,d2 as xe,w as _e,fe as ke,d1 as Fe,u as Oe,Z as qe,bI as De,aR as Be,aP as Le,aQ as $e,bE as H,ar as Ne}from"./index-40d672e9.js";const Ze=z(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"),Xe=z(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"),et=({isOpen:e,onConfirm:t,onClose:n,showBanner:o,environment:a,messageComponent:r})=>{const c=k("projectId"),{data:h}=F(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(S,{condition:d,show:u}),s(S,{condition:Boolean(o),show:T(ae,{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(A,{variant:"body2",color:"text.secondary",children:"Your suggestion:"}),r]})},tt="UPDATE_FEATURE_STRATEGY",at="UPDATE_PROJECT",st="READ_PROJECT_API_TOKEN",nt="CREATE_PROJECT_API_TOKEN",rt="DELETE_PROJECT_API_TOKEN",Ve=(e,t)=>{const n={};return t.parameters.forEach(o=>{n[o.name]=ze(e,o)}),{name:t.name,constraints:[],parameters:n}},ze=(e,t)=>t.name==="rollout"||t.name==="percentage"||t.type==="percentage"?"50":t.name==="stickiness"?"":t.name==="groupId"?e:t.type==="boolean"?"false":"",ot=()=>{const e=k("projectId"),t=k("featureId"),n=$("environmentId"),o=$("strategyName"),[a,r]=f.useState({}),[c,h]=f.useState([]),{strategyDefinition:l}=ne(o),u=re(),{addStrategyToFeature:d,loading:y}=oe(),{addChange:i}=U(),{setToastData:g,setToastApiError:v}=P(),{uiConfig:p}=ie(),{unleashUrl:m}=p,E=j(),{feature:b,refetchFeature:D}=N(e,t),B=f.useRef(b),{isChangeRequestConfigured:L}=ce(e),{refetch:M}=F(e),{trackEvent:G}=le(),{data:x,staleDataNotification:Q,forceRefreshCache:Z}=ue({unleashGetter:N,params:[e,t],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},b,{afterSubmitAction:D},ve);f.useEffect(()=>{B.current.name===""&&b.name&&(Z(b),B.current=b)},[b.name]),f.useEffect(()=>{l&&r(Ve(t,l))},[t,l]);const X=async C=>{await d(e,t,n,C),g({title:"Strategy created",type:"success",confetti:!0})},ee=async C=>{await i(e,n,{action:"addStrategy",feature:t,payload:C}),g({title:"Strategy added to draft",type:"success",confetti:!0}),M()},_=ge(a,c),te=async()=>{G("strategyTitle",{props:{hasTitle:Boolean(a.title),on:"create"}});try{L(n)?await ee(_):await X(_),D(),E(Te(e,t))}catch(C){v(R(C))}};return!x||!x.project?null:T(de,{modal:!0,title:he(o),description:pe,documentationLink:fe,documentationLinkLabel:ye,formatApiCode:()=>je(e,t,n,_,m),children:[s(me,{projectId:e,feature:x,strategy:a,setStrategy:r,segments:c,setSegments:h,environmentId:n,onSubmit:te,loading:y,permission:I,errors:u,isChangeRequest:L(n)}),Q]})},Ue=(e,t,n,o)=>{const a=new URLSearchParams({environmentId:n,strategyName:o});return`/projects/${e}/features/${t}/strategies/create?${a}`},je=(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=O("p")(({theme:e})=>({marginBottom:e.spacing(.5),fontSize:e.fontSizes.bodySize})),it=({open:e,environmentName:t,featureId:n,projectId:o,onClose:a})=>{const r=j(),c=Ue(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(Ee,{type:"button",permission:I,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."})]})},ct="You can not enable the environment before it has strategies",lt=e=>{const{setToastData:t,setToastApiError:n}=P(),{addChange:o}=U(),{refetch:a}=F(e),[r,c]=f.useState({isOpen:!1}),h=f.useCallback((d,y,i)=>{c({featureName:d,environment:y,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:Boolean(r.enabled)}}),a(),c(d=>({...d,isOpen:!1})),t({type:"success",title:"Changes added to the draft!"})}catch(d){n(R(d)),c(y=>({...y,isOpen:!1}))}},[o]);return{onChangeRequestToggle:h,onChangeRequestToggleClose:l,onChangeRequestToggleConfirm:u,changeRequestDialogDetails:r}},ut=({enabled:e,featureName:t,environment:n})=>T(A,{"data-testid":"update-enabled-message",children:[s("strong",{children:e?"Enable":"Disable"})," feature toggle"," ",s("strong",{children:t})," in ",s("strong",{children:n})]}),Ie=O(be)(({theme:e})=>({color:e.palette.warning.main,fontSize:e.fontSizes.bodySize})),gt=()=>s(Se,{arrow:!0,title:T(Y,{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(Ie,{})});var q={},Ye=Ce;Object.defineProperty(q,"__esModule",{value:!0});var K=q.default=void 0,We=Ye(Ae()),Je=Re,He=(0,We.default)((0,Je.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");K=q.default=He;const Ke=ke(),dt=({options:e,selectedOptions:t,indeterminateOptions:n,tagType:o,existingTags:a,disabled:r=!1,onChange:c})=>{const h=s(Fe,{fontSize:"small"});return s(W,{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(_e,{...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(m=>m.title===g.title))??!1;return T("li",{...i,children:[s(S,{condition:Boolean(g.inputValue),show:s(we,{sx:{mr:m=>m.spacing(.5)}}),elseShow:s(Pe,{icon:h,checkedIcon:s(xe,{fontSize:"small"}),indeterminateIcon:s(K,{fontSize:"small"}),sx:{mr:m=>m.spacing(.5)},checked:v&&!p,indeterminate:p})}),g.title]})},filterOptions:(i,g)=>{const v=Ke(i,g),{inputValue:p}=g,m=i.some(E=>p===E.title);return p!==""&&!m&&v.push({inputValue:p,title:`Create new value "${p}"`}),v},ListboxProps:{style:{maxHeight:200,overflow:"auto"}},onChange:c,renderInput:i=>s(J,{...i,label:"Select values",placeholder:"Select values"}),disabled:r})},Me=O("li")({flexDirection:"column"}),ht=({options:e,value:t,disabled:n=!1,onChange:o})=>{const a=Oe();return s(W,{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(Me,{...r,style:{alignItems:"flex-start",gap:a.spacing(.5)},children:[s(A,{variant:"body1",children:c.name}),s(A,{variant:"caption",children:c.description})]}),renderInput:r=>s(J,{...r,label:"Tag type",value:t}),onChange:o,ListboxProps:{style:{maxHeight:200,overflow:"auto"}}})},pt=()=>{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}},ft=(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(Boolean(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}},yt=({isStale:e,isOpen:t,projectId:n,featureId:o,onClose:a})=>{const{setToastData:r,setToastApiError:c}=P(),{patchFeatureToggle:h}=H(),l=s(A,{children:"Setting a toggle to stale marks it for cleanup"}),u=s(A,{children:"Setting a toggle to active marks it as in active use"}),d=e?"active":"stale",y=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:y,onClose:a,children:s(S,{condition:e,show:u,elseShow:l})})},mt=({isOpen:e,onClose:t,onConfirm:n,projectId:o,featureIds:a})=>{const{archiveFeatureToggle:r}=H(),{archiveFeatures:c}=Ne(),{setToastData:h,setToastApiError:l}=P(),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(S,{condition:u,show:T(Y,{children:[T("p",{children:["Are you sure you want to archive"," ",s("strong",{children:a==null?void 0:a.length})," feature toggles?"]}),s(S,{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{Ze as A,et as C,rt as D,ct as E,ot as F,st as R,ht as T,tt as U,gt as V,Xe as W,ut as a,it as b,pt as c,ft as d,dt as e,Ue as f,mt as g,yt as h,at as i,nt as j,lt as u};
@@ -1 +1 @@
1
- import{fi as p,u as m,bz as g,r as l,j as d}from"./index-36e7b066.js";import{d as c,L as x,C,a as f,b as S,P as h,c as q,T as k,p as v,e as M,f as L}from"./chartjs-adapter-date-fns.esm-16be4b37.js";import"./index-562cdc1c.js";import"./index-34846b98.js";const P=(e,i,s)=>{const t={label:"total requests",borderColor:e.palette.primary.main,backgroundColor:e.palette.primary.main,data:n(i,s,o=>o.yes+o.no),elements:{point:{radius:6,pointStyle:"circle"},line:{borderDash:[8,4]}}},a={label:"exposed",borderColor:e.palette.success.main,backgroundColor:e.palette.success.main,data:n(i,s,o=>o.yes),elements:{point:{radius:6,pointStyle:"triangle"}}},r={label:"not exposed",borderColor:e.palette.error.main,backgroundColor:e.palette.error.main,data:n(i,s,o=>o.no),elements:{point:{radius:6,pointStyle:"triangle",pointRotation:180}}};return{datasets:[a,r,t]}},n=(e,i,s)=>e.map(t=>({x:t.timestamp,y:s(t)})),R=(e,i,s,t)=>({locale:t.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,callbacks:{title:a=>p(a[0].parsed.x,t.locale)},itemSort:(a,r)=>r.parsed.y-a.parsed.y},legend:{position:"top",align:"end",labels:{boxWidth:10,boxHeight:10,usePointStyle:!0}},title:{text:_(s),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:(a,r,o)=>p(o[r].value,t.locale),color:e.palette.text.secondary}}}}),_=e=>e===1?"Requests in the last hour":`Requests in the last ${e} hours`;c.font={...c.font,family:"Sen",size:13,weight:"400"};const T=({metrics:e,hoursBack:i,statsSectionId:s})=>{const t=m(),{locationSettings:a}=g(),r=l.useMemo(()=>[...e].sort((y,b)=>y.timestamp.localeCompare(b.timestamp)),[e]),o=l.useMemo(()=>R(t,r,i,a),[t,r,i,a]),u=l.useMemo(()=>P(t,r,a),[t,r,a]);return d("div",{style:{height:400},children:d(x,{options:o,data:u,"aria-label":"A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.","aria-describedby":s})})};C.register(f,S,h,q,k,v,M,L);export{T as FeatureMetricsChart,T as default};
1
+ import{fi as p,u as m,bz as g,r as l,j as d}from"./index-40d672e9.js";import{d as c,L as x,C,a as f,b as S,P as h,c as q,T as k,p as v,e as M,f as L}from"./chartjs-adapter-date-fns.esm-f8cb8a7c.js";import"./index-0ef02266.js";import"./index-f9373b73.js";const P=(e,i,s)=>{const t={label:"total requests",borderColor:e.palette.primary.main,backgroundColor:e.palette.primary.main,data:n(i,s,o=>o.yes+o.no),elements:{point:{radius:6,pointStyle:"circle"},line:{borderDash:[8,4]}}},a={label:"exposed",borderColor:e.palette.success.main,backgroundColor:e.palette.success.main,data:n(i,s,o=>o.yes),elements:{point:{radius:6,pointStyle:"triangle"}}},r={label:"not exposed",borderColor:e.palette.error.main,backgroundColor:e.palette.error.main,data:n(i,s,o=>o.no),elements:{point:{radius:6,pointStyle:"triangle",pointRotation:180}}};return{datasets:[a,r,t]}},n=(e,i,s)=>e.map(t=>({x:t.timestamp,y:s(t)})),R=(e,i,s,t)=>({locale:t.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,callbacks:{title:a=>p(a[0].parsed.x,t.locale)},itemSort:(a,r)=>r.parsed.y-a.parsed.y},legend:{position:"top",align:"end",labels:{boxWidth:10,boxHeight:10,usePointStyle:!0}},title:{text:_(s),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:(a,r,o)=>p(o[r].value,t.locale),color:e.palette.text.secondary}}}}),_=e=>e===1?"Requests in the last hour":`Requests in the last ${e} hours`;c.font={...c.font,family:"Sen",size:13,weight:"400"};const T=({metrics:e,hoursBack:i,statsSectionId:s})=>{const t=m(),{locationSettings:a}=g(),r=l.useMemo(()=>[...e].sort((y,b)=>y.timestamp.localeCompare(b.timestamp)),[e]),o=l.useMemo(()=>R(t,r,i,a),[t,r,i,a]),u=l.useMemo(()=>P(t,r,a),[t,r,a]);return d("div",{style:{height:400},children:d(x,{options:o,data:u,"aria-label":"A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.","aria-describedby":s})})};C.register(f,S,h,q,k,v,M,L);export{T as FeatureMetricsChart,T as default};
@@ -1,7 +1,7 @@
1
- import{ay as yn,az as Sn,s as u,r as m,aA as bn,aB as Cn,aC as gt,j as t,aD as vn,aE as wn,c as jt,aF as k,aG as N,aH as Tn,f as c,aI as xn,C as x,aJ as G,aK as ue,aL as X,aM as ye,aN as An,aO as et,aP as ve,aQ as ke,aR as tt,u as nt,aS as Z,F as V,aT as ht,aU as ft,aV as at,aW as oe,aX as se,T as z,aY as he,a2 as q,ao as fe,aZ as De,a_ as me,A as re,a$ as zt,a4 as L,b0 as En,b1 as Rn,b2 as In,b3 as Fn,b4 as we,b5 as kn,b6 as pe,b7 as te,m as $e,b8 as Dn,b9 as $n,ba as Be,a8 as Pe,bb as Wt,bc as qt,bd as ot,be as Bn,bf as Ut,bg as Pn,H as Oe,bh as On,bi as Vn,bj as _n,a as Y,p as Mn,N as Ve,B as Se,bk as st,a9 as ce,bl as Ln,x as rt,bm as Re,E as Nn,bn as it,bo as Ie,P as jn,bp as zn,bq as ae,br as Wn,bs as qn,D as Un,bt as Hn,bu as Gn,bv as Yn,bw as Ht,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 ct,bI as oa,bJ as sa,ap as Gt,bK as ra,w as Yt,af as be,bL as ia,bM as ca,bN as Je,bO as Kt,bP as Jt,bQ as ie,bR as Xe,bS as la,ac as Xt,bT as Qt,a3 as lt,ad as da,bU as ua,bV as Zt,bW as pa,bX as ga,bY as en,bZ as ha,b_ as fa,am as ma,as as ya,b$ as de,c0 as mt,c1 as Sa,c2 as ba,c3 as Ca,c4 as va,ak as dt,al as wa,V as yt,c5 as Ta,c6 as xa,c7 as Aa,c8 as Ea,d as Ne,l as Ra,U as Ia,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 St,cc as _a,cd as tn,ce as Ma,ae as La,cf as bt,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-36e7b066.js";import{C as _e,U as nn,f as Za,u as eo,a as to,E as no,V as ao,b as oo,c as so,d as ro,T as io,e as co,F as lo,A as uo,W as po,g as go,h as ho}from"./FeatureArchiveDialog-4bbeeb8f.js";import{S as fo}from"./StrategyItemContainer-e26123be.js";import{v as je}from"./v4-a960c1f4.js";function mo(e){return yn("MuiCardContent",e)}Sn("MuiCardContent",["root"]);const yo=["className","component"],So=e=>{const{classes:n}=e;return wn({root:["root"]},mo,n)},bo=u("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),Co=m.forwardRef(function(n,a){const s=bn({props:n,name:"MuiCardContent"}),{className:o,component:i="div"}=s,r=Cn(s,yo),l=gt({},s,{component:i}),d=So(l);return t(bo,gt({as:i,className:vn(d.root,o),ownerState:l,ref:a},r))}),vo=Co,wo=jt(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"),To=jt(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),xo=u("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Ao=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n);return a.name?t(xo,{children:t(Tn,{title:"Event log",feature:n,displayInline:!0})}):null},Eo=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"}})),Ro=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Io=u("div")({display:"flex",alignItems:"center"}),Fo=u("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),ko=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),Ct=u("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),vt=u("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),Do=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n),{project:s,description:o,type:i}=a,r=An(i);return t(Eo,{children:c(Ro,{children:[c(Io,{"data-loading":!0,children:[t(r,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",c(Fo,{children:[xn(i||"")," toggle"]})]}),c(ko,{children:[c(Ct,{"data-loading":!0,children:["Project: ",s]}),t(x,{condition:Boolean(o),show:c(Ct,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(vt,{children:[t("p",{children:o}),t(G,{projectId:e,permission:ue,component:X,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(vt,{children:["No description."," ",t(G,{projectId:e,permission:ue,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},wt={lastHourUsage:[],seenApplications:[]},$o=(e,n,a={})=>{const s=async()=>{const g=ve(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(ke("feature metrics"));return h.ok?h.json():wt},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||wt,error:r,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},Bo=e=>({yes:0,no:0,environment:e,timestamp:""}),Po=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||Bo(a.name)),Oo=({enabled:e,className:n})=>{const a=nt(),s=e?"Environment enabled":"Environment disabled",o={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)},i={fill:a.palette.common.white,width:"16px",height:"16px"};return t("div",{style:o,className:n,children:t(To,{style:i,titleAccess:s})})},an=()=>t(re,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Vo=({onRemove:e,onClose:n,isOpen:a})=>t(se,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(an,{})}),_o=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Mo=({onRemove:e,onClose:n,isOpen:a})=>c(se,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(an,{}),t(_o,{children:t(z,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(z,{fontWeight:"bold",children:"Remove strategy"})]}),Lo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=he(),{setToastData:i,setToastApiError:r}=q(),l=fe(),{refetchFeature:d}=N(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),d(),l(zt(e,n))}catch(h){r(L(h))}}},No=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=De(),{refetch:i}=me(e),{setToastData:r,setToastApiError:l}=q();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),r({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(L(g))}}},jo=({projectId:e,featureId:n,environmentId:a,strategyId:s,disabled:o,icon:i})=>{const[r,l]=m.useState(!1),{isChangeRequestConfigured:d}=Z(e),p=Lo({featureId:n,projectId:e,strategyId:s,environmentId:a}),g=No({featureId:n,projectId:e,strategyId:s,environmentId:a});return c(V,{children:[t(x,{condition:Boolean(i),show:t(G,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:o,permission:ht,"data-testid":ft,tooltipProps:{title:"Remove strategy"},type:"button",children:t(at,{})}),elseShow:t(oe,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:o,permission:ht,"data-testid":ft,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(x,{condition:d(a),show:t(Mo,{isOpen:r,onClose:()=>l(!1),onRemove:async h=>{await g(h),l(!1)}}),elseShow:t(Vo,{isOpen:r,onClose:()=>l(!1),onRemove:p})})]})},zo=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s));var Wo=En(et,zo);const on=(e,n)=>{const{refetchFeature:a}=N(e,n),s=Rn(e,n),{data:o,error:i,mutate:r}=Wo(["useFeatureImmutable",s],()=>In(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}},ut=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=q(),{addChange:i}=De(),{refetch:r}=me(e),[l,d]=m.useState({isOpen:!1}),p=m.useCallback((T,I,y)=>{d({featureName:n,environment:T,fromEnvironment:y,strategy:I,isOpen:!0})},[]),g=m.useCallback((T,I,y)=>{d({featureName:n,environment:T,fromEnvironment:y,strategies:I,isOpen:!0})},[]),h=m.useCallback(()=>{d({isOpen:!1})},[]),b=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(T){o(L(T)),d({isOpen:!1})}},[i]),v=m.useCallback(async()=>{try{await Promise.all(l.strategies.map(T=>i(e,l.environment,{feature:l.featureName,action:a,payload:T}))),r(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(T){o(L(T)),d({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:v,changeRequestDialogDetails:l}},qo=({payload:e,fromEnvironment:n,environment:a})=>c(z,{children:[c("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Uo=({environmentId:e,environments:n,strategy:a})=>{const s=k("projectId"),o=k("featureId"),[i,r]=m.useState(null),l=Boolean(i),{addStrategyToFeature:d}=he(),{setToastData:p,setToastApiError:g}=q(),{refetchFeature:h}=N(s,o),{refetchFeature:b}=on(s,o),v=()=>{r(null)},T=kn(s),{isChangeRequestConfigured:I}=Z(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:C,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:R}=ut(s,o,"addStrategy"),B=async $=>{const{id:P,...D}={...a,targetEnvironment:$};if(I($)){await w($,{id:P,...D},e);return}try{await d(s,o,$,a),h(),b(),p({title:"Strategy created",text:`Successfully copied a strategy to ${$}`,type:"success"})}catch(U){g(L(U))}v()},O=n.some($=>T(pe,$));return c("div",{children:[t(_e,{isOpen:y.isOpen,onClose:C,environment:y==null?void 0:y.environment,onConfirm:R,messageComponent:t(qo,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(te,{title:`Copy to another environment${O?"":" (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:$=>{r($.currentTarget)},"data-testid":Dn,disabled:!O,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($=>{const P=T(pe,$);return t(te,{title:P?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Pe,{onClick:()=>B($),disabled:!P,children:[t(x,{condition:!P,show:t(Wt,{children:t(qt,{fontSize:"small"})})}),c(ot,{children:["Copy to ",$]})]})})},$)})})]})},sn=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=N(e,a),{setStrategyDisabledState:i}=he(),{setToastData:r,setToastApiError:l}=q(),d=p=>async()=>{try{await i(e,a,n,s.id,!p),r({title:`Strategy ${p?"enabled":"disabled"}`,type:"success"}),o()}catch(g){l(L(g))}};return{onDisable:d(!1),onEnable:d(!0)}},rn=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=De(),{refetch:i}=me(e),{setToastData:r,setToastApiError:l}=q(),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(g){l(L(g))}};return{onSuggestDisable:d(!1),onSuggestEnable:d(!0)}},Ho=({...e})=>{const{projectId:n,environmentId:a}=e,[s,o]=m.useState(!1),{onDisable:i}=sn({...e}),{onSuggestDisable:r}=rn({...e}),{isChangeRequestConfigured:l}=Z(n),d=l(a);return c(V,{children:[t(G,{onClick:()=>o(!0),projectId:n,environmentId:a,permission:nn,tooltipProps:{title:"Disable strategy"},type:"button",children:t(Bn,{})}),t(se,{title:d?"Add disabling strategy to change request?":"Are you sure you want to disable this strategy?",open:s,primaryButtonText:d?"Add to draft":"Disable strategy",secondaryButtonText:"Cancel",onClick:g=>{g.preventDefault(),d?r():i(),o(!1)},onClose:()=>o(!1),children:t(x,{condition:d,show:t(Ut,{environment:a}),elseShow:t(re,{severity:"error",children:"Disabling the strategy will change which users receive access to the feature."})})})]})},Go=({...e})=>{const{projectId:n,environmentId:a}=e,[s,o]=m.useState(!1),{onEnable:i}=sn({...e}),{onSuggestEnable:r}=rn({...e}),{isChangeRequestConfigured:l}=Z(n),d=l(a);return c(V,{children:[t(G,{onClick:()=>o(!0),projectId:n,environmentId:a,permission:nn,tooltipProps:{title:"Enable strategy"},type:"button",children:t(Pn,{})}),t(se,{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:g=>{g.preventDefault(),d?r():i(),o(!1)},onClose:()=>o(!1),children:t(x,{condition:d,show:t(Ut,{environment:a}),elseShow:t(re,{severity:"error",children:"Enabling the strategy will change which users receive access to the feature."})})})]})},Yo=({...e})=>e.strategy.disabled?t(Go,{...e}):t(Ho,{...e}),Ko=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:r})=>{var h;const{uiConfig:l}=Oe(),d=k("projectId"),p=k("featureId"),g=On(d,p,e,n.id);return t(fo,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:c(V,{children:[r,t(x,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(Uo,{environmentId:e,environments:o,strategy:n})}),t(G,{permission:Vn,environmentId:e,projectId:d,component:X,to:g,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(ye,{})}),t(x,{condition:Boolean((h=l==null?void 0:l.flags)==null?void 0:h.strategyDisable),show:()=>t(Yo,{projectId:d,featureId:p,environmentId:e,strategy:n})}),t(jo,{projectId:d,featureId:p,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(_n,{strategy:n})})},Jo=(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)},Xo=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:r,onDragEnd:l})=>{const d=k("projectId"),p=k("featureId"),g=m.useRef(null),h=Jo(d,p,a,e.id);return c(Y,{ref:g,onDragOver:r(g,n),sx:{opacity:o?"0.5":"1"},children:[t(x,{condition:n>0,show:t(Mn,{text:"OR"})}),t(Ko,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(g,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(Qo,{change:h})})]},e.id)},Qo=({change:e})=>{const n=nt();return Ve(n.breakpoints.down("sm"))?null:c(Y,{sx:{mr:1.5},children:[t(x,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Se,{color:"warning",children:"Modified in draft"})}),t(x,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Se,{color:"error",children:"Deleted in draft"})})]})},Zo=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}})),es=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})),cn=({children:e})=>t(Zo,{children:t(es,{children:e})}),ts=({environmentId:e,environments:n,onClick:a})=>{const s=k("projectId"),[o,i]=m.useState(null),r=Boolean(o),{hasAccess:l}=m.useContext(st),d=n.some(p=>l(pe,s,p));return c("div",{children:[t(te,{title:d?"":"(Access denied)",children:t("div",{children:t(ce,{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 g=l(pe,s,p);return t(te,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Pe,{onClick:()=>a(p),disabled:!g,children:[t(x,{condition:!g,show:t(Wt,{children:t(qt,{fontSize:"small"})})}),c(ot,{children:["Copy from ",p]})]})})},p)})})]})},ns=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),as=({payload:e,fromEnvironment:n,environment:a})=>c(ns,{children:[t(z,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>c(z,{children:[c("strong",{children:[we((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),c(z,{children:["from ",n," to ",a]})]}),os=({payload:e,environment:n})=>c(V,{children:[t(z,{component:"span",children:"Add "}),c("strong",{children:[we((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),ss=u(Ln)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),Tt=({title:e,children:n,featureId:a,projectId:s,environmentId:o,strategy:i,Icon:r,onAfterAddStrategy:l})=>{const{addStrategyToFeature:d}=he(),{setToastApiError:p}=q(),{isChangeRequestConfigured:g}=Z(s),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:v,onChangeRequestAddStrategyClose:T}=ut(s,a,"addStrategy");return c(V,{children:[t(ss,{variant:"outlined",children:c(vo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(z,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(z,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(Y,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(oe,{permission:pe,projectId:s,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,i):(await d(s,a,o,i),l())}catch(y){p(L(y))}},children:"Use template"})})]})}),t(_e,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:v,messageComponent:t(os,{environment:o,payload:h.strategy})})]})},rs=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}})),is=u("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),cs=u(rt)(({theme:e})=>({fontWeight:e.fontWeight.bold})),ls=u(X)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),ds=({projectId:e,featureId:n,environmentId:a,strategy:s})=>{const o=Re(s.name),i=we(s.name),r=Za(e,n,a,s.name);return c(ls,{to:r,children:[t(rs,{children:t(o,{})}),c("div",{children:[t(cs,{text:s.displayName||i,maxWidth:"200",maxLength:25}),t(is,{children:s.description})]})]})},us=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=Nn(),o=m.useMemo(()=>s.filter(i=>!i.deprecated),[s]);return t(it,{dense:!0,children:o.map(i=>t(Ie,{children:t(ds,{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=Boolean(r),p=d?"FeatureStrategyMenuPopover":void 0,g=()=>{l(void 0)};return c("div",{onClick:b=>b.stopPropagation(),children:[t(oe,{permission:pe,projectId:n,environmentId:s,onClick:b=>{l(b.currentTarget)},"aria-labelledby":p,variant:o,sx:{minWidth:i?"282px":"auto"},children:e}),t(jn,{id:p,open:d,anchorEl:r,onClose:g,onClick:g,children:t(us,{projectId:n,featureId:a,environmentId:s})})]})},ps=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),gs=u("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),hs=u("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),fs=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=he(),{setToastData:o,setToastApiError:i}=q(),{refetchFeature:r}=N(e,n),{refetchFeature:l}=on(e,n),{feature:d}=N(e,n),p=d==null?void 0:d.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:g}=Z(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:v,onChangeRequestAddStrategyClose:T}=ut(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"})},y=async w=>{var B;const R=((B=p==null?void 0:p.find(O=>O.name===w))==null?void 0:B.strategies)||[];if(g(a)){await b(a,R,w);return}try{await Promise.all(R.map(O=>{const{id:$,...P}={...O,environment:a};return s(e,n,a,P)})),I(!0)}catch(O){i(L(O))}},C=p&&p.length>0;return c(V,{children:[t(_e,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:v,messageComponent:t(as,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(ps,{children:[t(gs,{children:"You have not defined any strategies yet."}),c(hs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Y,{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(x,{condition:C,show:t(ts,{environmentId:a,environments:p.map(w=>w.name),onClick:y})})]}),t(Y,{sx:{width:"100%",mt:3},children:t(cn,{children:"Or use a strategy template"})}),c(Y,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(Tt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:I,Icon:Re("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(Tt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:I,Icon:Re("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:d.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},ms=u("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ys=u("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Ss=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=k("projectId"),o=k("featureId"),{setStrategiesSortOrder:i}=he(),{setToastData:r,setToastApiError:l}=q(),{refetchFeature:d}=N(s,o),[p,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,b]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const v=async C=>{try{await i(s,o,e.name,C),d(),r({title:"Order of strategies updated",type:"success"})}catch(w){l(L(w))}},T=(C,w)=>R=>{var B;b({id:p[w].id,index:w,height:((B=C.current)==null?void 0:B.offsetHeight)||0}),C!=null&&C.current&&(R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/html",C.current.outerHTML),R.dataTransfer.setDragImage(C.current,20,20))},I=C=>(w,R)=>B=>{if(h===null||w.current===null||h.index===R||C===h.id)return;const{top:O,bottom:$}=w.current.getBoundingClientRect(),P=B.clientY-O<h.height,D=$-B.clientY<h.height,U=h.index>R;if(P&&U||D&&!U){const K=[...p],J=K.splice(h.index,1)[0];K.splice(R,0,J),g(K),b({...h,index:R})}},y=()=>{b(null),v(p.map((C,w)=>({id:C.id,sortOrder:w})))};return t(ms,{children:c(ys,{children:[t(x,{condition:p.length>0&&n,show:()=>t(re,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(x,{condition:p.length>0,show:t(V,{children:p.map((C,w)=>t(Xo,{strategy:C,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===C.id,onDragStartRef:T,onDragOver:I(C.id),onDragEnd:y},C.id))}),elseShow:t(fs,{projectId:s,featureId:o,environmentId:e.name})})]})})},ln=(e,n)=>e===0?0:Math.round(n/e*100);var Me={},Le={};Object.defineProperty(Le,"__esModule",{value:!0});Le.defaultOptions=void 0;Le.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 bs(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=bs;function Cs(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}ge.roundTo=Cs;Object.defineProperty(Me,"__esModule",{value:!0});Me.millify=void 0;const ze=Le,xt=ge,At=1e3;function*Et(e){let n=At;for(;;){const a=e/n;if(a<1)return;yield a,n*=At}}function dn(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=xt.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 Et(o))o=v,r+=1;if(r>=s.units.length)return e.toString();let d=xt.roundTo(o,s.precision);for(const v of Et(d))d=v,r+=1;const p=(a=s.units[r])!==null&&a!==void 0?a:"",g=s.lowercase?p.toLowerCase():p,h=s.space?" ":"",b=d.toString().replace(ze.defaultOptions.decimalSeparator,s.decimalSeparator);return`${i}${b}${h}${g}`}Me.millify=dn;var vs=Me.default=dn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=vs(e,{precision:a}),o=!0);const i=t("span",{"data-testid":zn,children:s});return t(x,{condition:o,show:t(te,{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})),un=({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(ae,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ae,{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(ae,{item:!0,xs:12,sm:4,children:c(We,{children:[t(qe,{children:"Exposure %"}),c(Ue,{children:[ln(e+n,e),"%"]}),c(He,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(ae,{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,"."]})]})})]})},ws=({environmentMetric:e})=>e?c(V,{children:[t(cn,{children:"Feature toggle exposure"}),t("div",{children:t(un,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Rt=u("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),It=u("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ft=u("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),kt=u("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Ts=u(Wn)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),xs=u("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),As=({environmentMetric:e,disabled:n=!1})=>{const a=qn();if(!e)return null;const s=e.yes+e.no,o=ln(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Rt,{children:[c(It,{children:[c(Ft,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),c(kt,{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(Ts,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Rt,{children:[c(It,{children:[c(Ft,{children:[o,"%"]}),c(kt,{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(xs,{"data-loading":!0,children:t(Un,{percentage:o,size:"3rem"})})]})},Es=({strategyName:e})=>{const n=Re(e);return t(te,{title:we(e),arrow:!0,children:t(Rs,{children:t(n,{})})})},Rs=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)}})),Is=({strategies:e})=>e!=null&&e.length?t(Fs,{"aria-label":"Feature strategies",children:e.map(n=>t(ks,{children:t(Es,{strategyName:n.name})},n.id))}):null,Fs=u("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),ks=u("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Ds=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})),$s=u(Hn)({boxShadow:"none",background:"none"}),Bs=u(Gn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Ps=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)}})),Os=u(Ss)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Vs=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})),_s=u("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Ms=u(Oo)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ls=u(rt)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Ns=u("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),js=({env:e})=>{var p;const n=k("projectId"),a=k("featureId"),{metrics:s}=$o(n,a),{feature:o}=N(n,a),{value:i}=Ht(),l=Po(o==null?void 0:o.environments,s).find(g=>g.environment===e.name),d=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(x,{condition:!Boolean(new Set(i.hiddenEnvironments).has(e.name)),show:t(Ds,{enabled:e.enabled,children:c($s,{"data-testid":`${Kn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(Bs,{expandIcon:t(Jn,{titleAccess:"Toggle"}),children:[c(Vs,{"data-loading":!0,enabled:e.enabled,children:[c(_s,{children:[t(Ms,{enabled:e.enabled}),t("div",{children:t(Ls,{text:e.name,maxWidth:"100",maxLength:15})}),t(x,{condition:!e.enabled,show:t(Se,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),c(Ns,{children:[t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(Is,{strategies:d==null?void 0:d.strategies})]})]}),t(As,{environmentMetric:l,disabled:!e.enabled})]}),c(Ps,{enabled:e.enabled,children:[t(Os,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(x,{condition:(((p=d==null?void 0:d.strategies)==null?void 0:p.length)||0)>0,show:c(V,{children:[t(Y,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(ws,{environmentMetric:l})]})})]})]})})})},zs=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n);if(!a)return null;const{environments:s}=a;return t(V,{children:s==null?void 0:s.map(o=>t(js,{env:o},o.name))})},Ws=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),qs=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Us=({feature:e,header:n})=>{const{locationSettings:a}=Xn();return c(Ws,{children:[n,c("div",{"data-loading":!0,children:[t(qs,{children:"Created at:"}),t("span",{children:Qn(Zn(e.createdAt),a.locale)})]})]})},Hs=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}})),Gs=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Hs,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(x,{condition:n.has(e.name),show:t(ea,{}),elseShow:t(ta,{})})}),Ys=u("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Ks=u("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Js=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:r,enabled:l}=e,d=k("projectId"),p=k("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=Te(),{refetchFeature:b}=N(d,p),{setToastData:v,setToastApiError:T}=q(),{isChangeRequestConfigured:I}=Z(d),{onChangeRequestToggle:y,onChangeRequestToggleClose:C,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:R}=eo(d),B=async()=>{try{await g(d,p,r),v({type:"success",title:`Available in ${r}`,text:`${p} is now available in ${r} based on its defined strategies.`}),b(),n&&n()}catch(D){D instanceof Error&&D.message===no?a():T(L(D))}},O=async()=>{try{await h(d,p,r),v({type:"success",title:`Unavailable in ${r}`,text:`${p} is unavailable in ${r} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(D){T(L(D))}},$=async D=>{if(I(r)){D.preventDefault(),y(p,r,!l);return}if(l){await O();return}await B()},P=c(V,{children:[" ",c("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(rt,{text:r,maxWidth:"120",maxLength:15})]});return c(Ys,{children:[c(Ks,{children:[t(na,{tooltip:l?`Disable feature in ${r}`:`Enable feature in ${r}`,permission:aa,projectId:d,checked:l,onChange:$,environmentId:r}),s??P]}),t(Gs,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i}),t(_e,{isOpen:R.isOpen,onClose:C,environment:R==null?void 0:R.environment,onConfirm:w,messageComponent:t(to,{enabled:R==null?void 0:R.enabled,featureName:R==null?void 0:R.featureName,environment:R.environment})})]})},Xs=u("div")(({theme:e})=>({padding:e.spacing(3)})),Qs=u("div")(()=>({display:"flex",flexDirection:"column"})),Zs=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"})),Dt=u("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),tr=u(ct)(()=>({"&: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 g;return p.enabled&&((g=p.variants)==null?void 0:g.length)});return c(Xs,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const g=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,h=p.variants??[],b=h.length>0&&c(V,{children:[t(Dt,{}),t(te,{title:"View variants",arrow:!0,describeChild:!0,children:t(tr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),v=p.enabled&&h.length===0&&d;return t(Js,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(p.name),i(!0)},children:c(Qs,{children:[t(Zs,{children:p.name}),c(er,{children:[g,b,t(x,{condition:v,show:c(V,{children:[t(Dt,{}),t(ao,{})]})})]})]})},p.name)}),t(oo,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},pn=(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}=oa(Boolean(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})),$t=(e,n)=>e.map(a=>({value:a.title,type:n})),gn=({open:e,setOpen:n})=>{const{tagTypes:a}=sa(),s=k("featureId"),{createTag:o}=so(),{updateFeatureTags:i,loading:r}=Te(),{tags:l,refetch:d,loading:p}=pn(s),{setToastData:g}=q(),[h,b]=m.useState({name:"simple",description:"Simple tag to get you started",icon:""}),v=r||p,[T,I]=m.useState(0),{trackEvent:y}=Gt(),[C,w]=m.useState(Ge(l.filter(f=>f.type===h.name))),{tags:R,refetch:B}=ro(h.name),O=m.useMemo(()=>Ge(R),[R]);m.useEffect(()=>{l&&h&&w(Ge(l.filter(f=>f.type===h.name)))},[JSON.stringify(l),h]);const $=()=>{n(!1),w([])};function P(f,S){const E=f.filter(M=>M.type===h.name).filter(M=>!S.find(j=>M.value===j.value&&M.type===j.type)),_=S.filter(M=>M.type===h.name).filter(M=>!f.find(j=>M.value===j.value&&M.type===j.type));return I(E.length+_.length),{added:E,removed:_}}const D=f=>f.filter(S=>!S.title.startsWith("Create")),U=async(f,S)=>{try{await i(s,{addedTags:f,removedTags:S}),await d()}catch(E){const _=L(E);g({type:"error",title:"Failed to add tag",text:_,confetti:!1})}},K=(f,S)=>{let E="We successfully";return f>0&&(E=E.concat(` added ${f} new tag${f>1?"s":""}`)),f>0&&S>0&&(E=E.concat(" and ")),S>0&&(E=E.concat(` removed ${S} tag${S>1?"s":""}`)),E},J=async f=>{f.preventDefault();const S=$t(D(C),h.name),{added:E,removed:_}=P(S,l);T>0&&(await U(E,_),T>1&&y("suggest_tags",{props:{eventType:"multiple_tags_added"}}),T>0&&g({type:"success",title:`Updated tag${E.length>1?"s":""} to toggle`,text:K(E.length,_.length),confetti:!0})),I(0),w([]),n(!1)},ne=(f,S)=>{S!=null&&typeof S!="string"&&(f.preventDefault(),b(S),w([]),I(0))},ee=(f,S,E)=>{const _=ra(S);E==="selectOption"&&S.forEach((j,H)=>{if(typeof j!="string"&&j.inputValue&&j.inputValue!==""){const xe={value:j.inputValue,type:h.name};o(xe).then(()=>{y("suggest_tags",{props:{eventType:"tag_created"}}),B()}),j.title=j.inputValue,j.inputValue="",_[H]=j}});const M=$t(D(_),h.name);P(M,l),w(_)},A="add-tag-form";return t(se,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:J,disabledPrimaryButton:v||T===0,onClose:$,formId:A,children:c(V,{children:[t(z,{paragraph:!0,sx:{marginBottom:f=>f.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:A,onSubmit:J,children:c(ar,{children:[t(io,{options:a,value:h,onChange:ne}),t(co,{options:O,existingTags:l,tagType:h,selectedOptions:C,onChange:ee})]})})]})})},or=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),sr=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),rr=u(Yt)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ir=u(be)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),cr=u(ce)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),lr=({feature:e,header:n})=>{const{tags:a,refetch:s}=pn(e.name),{deleteTagFromFeature:o}=Te(),[i,r]=m.useState(!1),[l,d]=m.useState(!1),[p,g]=m.useState(),{setToastData:h,setToastApiError:b}=q(),{hasAccess:v}=m.useContext(st),T=v(ue,e.project),I=async()=>{if(p)try{await o(e.name,p.type,p.value),s(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){b(L(y))}};return c(or,{children:[n,t(sr,{children:a.map(y=>{const C=`${y.type}:${y.value}`;return t(rr,{label:C,deleteIcon:t(ia,{titleAccess:"Remove"}),onDelete:T?()=>{d(!0),g(y)}:void 0},C)})}),t(x,{condition:T,show:c(V,{children:[t(x,{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(gn,{open:i,setOpen:r}),c(se,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),g(void 0)},onClick:()=>{d(!1),I(),g(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=k("projectId"),s=k("featureId"),{feature:o}=N(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(Us,{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}=Gt(),{value:n,setValue:a}=Ht(),[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=k("projectId"),a=k("featureId"),s=zt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=pr(),r=()=>e(s);return Kt(a),c(gr,{children:[c("div",{children:[t(Do,{}),t(ur,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(hr,{children:t(zs,{})}),c(Jt,{children:[t(ie,{path:"strategies/create",element:t(Xe,{label:"Create feature strategy",onClose:r,open:!0,children:t(lo,{})})}),t(ie,{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(g=>g.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(Xt,{...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(Qt)(({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(Xt)(()=>({width:"100%"})),wr=({overrides:e,overridesDispatch:n})=>{const{context:a}=lt(),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 h;const d=a.find(({name:b})=>b===r.contextName),p=((h=d==null?void 0:d.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=r.values.filter(b=>p.includes(b));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:b=>n({type:"UPDATE_TYPE_AT",payload:[l,b.target.value]})}),c(br,{children:[t(x,{condition:Boolean(p&&p.length>0),show:t(da,{multiple:!0,id:`override-select-${l}`,isOptionEqualToValue:(b,v)=>b===v,options:p,onChange:i(l),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(vr,{...b,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(te,{title:"Remove",arrow:!0,children:t($e,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:l})},children:t(at,{})})})]})]},`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 Q=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Q||{});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(te)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),hn=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Bt=u(hn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),Rr=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),Ir=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%"}})),Pt=u(Zt)(()=>({width:"100%"})),kr=u("div")(({theme:e})=>({marginLeft:e.spacing(3)})),Dr=u(Zt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),$r=u("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),fn=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(fn)({alignItems:"end",justifyContent:"space-between"}),Pr=u(Qt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),Or=u(ce)(({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:""},Mr=({variant:e,variants:n,updateVariant:a,removeVariant:s,apiPayload:o})=>{const[i,r]=m.useState(e.name),[l,d]=m.useState(e.weightType===Q.FIX),[p,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||_r),[v,T]=xr(e.overrides||[]),{context:I}=lt(),[y,C]=m.useState({}),w=f=>{C(S=>({...S,[f]:void 0}))},R=(f,S)=>{C(E=>({...E,[f]:S}))};m.useEffect(()=>{var f;w("percentage"),(f=o.error)!=null&&f.includes("%")&&R("percentage","Total weight must equal 100%")},[o.error]);const B=!e.new,O=n.filter(({id:f,weightType:S})=>f!==e.id&&S===Q.VARIABLE).length>0,$=f=>{const S=f.weightType===Q.VARIABLE,E=n.some(M=>M.weightType===Q.FIX),_=n.filter(M=>M.weightType===Q.VARIABLE).length===1;return E&&_&&S},P=f=>{w("name"),ne(f,e.id)||R("name","A variant with that name already exists for this environment."),r(f)},D=f=>{(f===""||ee(f))&&g(f)},U=f=>{A(f)||R("payload","Invalid JSON.")},K=()=>{I.length>0&&T({type:"ADD",payload:{contextName:I[0].name,values:[]}})},J=f=>Boolean(f.length),ne=(f,S)=>B||!n.some(E=>E.name===f&&E.id!==S),ee=f=>{if(!l)return!0;if(f===""||f.match(/\.[0-9]{2,}$/))return!1;const S=Number(f);return S>=0&&S<=100},A=f=>{try{return f.type==="json"&&JSON.parse(f.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:i,weight:Number(l?p:100)*10,weightType:l?Q.FIX:Q.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:v.map(f=>({contextName:f.contextName,values:f.values})).filter(f=>f.values&&f.values.length>0),isValid:J(i)&&ne(i,e.id)&&ee(p)&&A(h)&&!o.error})},[i,l,p,h,v]),m.useEffect(()=>{l||g(String(e.weight/10))},[e.weight]),c(Ar,{"data-testid":"VARIANT",children:[t(Er,{arrow:!0,title:$(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:$(e),children:t(at,{})})})}),c(Br,{children:[c($r,{children:[t(hn,{children:"Variant name"}),t(Rr,{children:"This will be used to identify the variant in your code"}),t(Pt,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:Boolean(y.name),errorText:y.name,value:i,onChange:f=>P(f.target.value),disabled:B,required:!0})]}),t(x,{condition:O,show:c(kr,{children:[t(Ir,{label:"Custom percentage",control:t(pa,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:l,onChange:f=>d(f.target.checked)})}),t(Dr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(y.percentage),errorText:y.percentage,value:p,onChange:f=>D(f.target.value),required:l,disabled:!l,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(ga,{position:"end",children:"%"})}})]})})]}),c(Bt,{children:["Payload",t(Je,{tooltip:"Passed along with the the variant object."})]}),c(fn,{children:[t(Pr,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:Vr,onChange:f=>{w("payload"),b(S=>({...S,type:f.target.value}))}}),t(Fr,{children:t(Pt,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:f=>{w("payload"),b(S=>({...S,value:f.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>U(h),error:Boolean(y.payload),errorText:y.payload})})]}),c(Bt,{children:["Overrides",t(Je,{tooltip:"Here you can specify which users should get this variant."})]}),t(wr,{overrides:v,overridesDispatch:T}),t("div",{children:t(Or,{onClick:K,variant:"text",color:"primary","data-testid":"VARIANT_ADD_OVERRIDE_BUTTON",children:"Add override"})})]})},Lr=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(en,{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(re)(({theme:e})=>({marginBottom:e.spacing(2)})),qr=u(re)(({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)})),Ot=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(ce)(({theme:e})=>({marginLeft:e.spacing(3)})),Xr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const r=k("projectId"),l=k("featureId"),{uiConfig:d}=Oe(),{context:p}=lt(),{defaultStickiness:g,loading:h}=fa(r),{isChangeRequestConfigured:b}=Z(r),{data:v}=me(r),{changeRequestInReviewOrApproved:T,alert:I}=Sa(v),y=(e==null?void 0:e.variants)||[],[C,w]=m.useState([]),[R,B]=m.useState();m.useEffect(()=>{h||w(y.length?y.map(F=>({...F,isValid:!0,new:!1,id:je()})):[{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(C==null?void 0:C.length)>0?C[0].stickiness:g,new:!0,isValid:!1,id:je()}])},[n,h]);const O=(F,W)=>{w(le=>mt(le.map(Ae=>Ae.id===W?F:Ae),1e3))},$=()=>{const F=je();w(W=>[...W,{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(W==null?void 0:W.length)>0?W[0].stickiness:g,new:!0,isValid:!1,id:F}]),B(F)};m.useEffect(()=>{if(R){const F=document.getElementById(`variant-name-input-${R}`);F==null||F.scrollIntoView({behavior:"smooth",block:"center"}),F==null||F.focus({preventScroll:!0}),B(void 0)}},[R]);const P=C.map(({new:F,isValid:W,id:le,...Ae})=>Ae),D=s(y,P),U=o(P),K=async F=>{F.preventDefault(),i(P)},J=()=>f?`curl --location --request POST '${d.unleashUrl}/api/admin/projects/${r}/environments/${e==null?void 0:e.name}/change-requests' \\
1
+ import{ay as yn,az as Sn,s as u,r as m,aA as bn,aB as Cn,aC as gt,j as t,aD as vn,aE as wn,c as jt,aF as k,aG as N,aH as Tn,f as c,aI as xn,C as x,aJ as G,aK as ue,aL as X,aM as ye,aN as An,aO as et,aP as ve,aQ as ke,aR as tt,u as nt,aS as Z,F as V,aT as ht,aU as ft,aV as at,aW as oe,aX as se,T as z,aY as he,a2 as q,ao as fe,aZ as De,a_ as me,A as re,a$ as zt,a4 as L,b0 as En,b1 as Rn,b2 as In,b3 as Fn,b4 as we,b5 as kn,b6 as pe,b7 as te,m as $e,b8 as Dn,b9 as $n,ba as Be,a8 as Pe,bb as Wt,bc as qt,bd as ot,be as Bn,bf as Ut,bg as Pn,H as Oe,bh as On,bi as Vn,bj as _n,a as Y,p as Mn,N as Ve,B as Se,bk as st,a9 as ce,bl as Ln,x as rt,bm as Re,E as Nn,bn as it,bo as Ie,P as jn,bp as zn,bq as ae,br as Wn,bs as qn,D as Un,bt as Hn,bu as Gn,bv as Yn,bw as Ht,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 ct,bI as oa,bJ as sa,ap as Gt,bK as ra,w as Yt,af as be,bL as ia,bM as ca,bN as Je,bO as Kt,bP as Jt,bQ as ie,bR as Xe,bS as la,ac as Xt,bT as Qt,a3 as lt,ad as da,bU as ua,bV as Zt,bW as pa,bX as ga,bY as en,bZ as ha,b_ as fa,am as ma,as as ya,b$ as de,c0 as mt,c1 as Sa,c2 as ba,c3 as Ca,c4 as va,ak as dt,al as wa,V as yt,c5 as Ta,c6 as xa,c7 as Aa,c8 as Ea,d as Ne,l as Ra,U as Ia,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 St,cc as _a,cd as tn,ce as Ma,ae as La,cf as bt,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-40d672e9.js";import{C as _e,U as nn,f as Za,u as eo,a as to,E as no,V as ao,b as oo,c as so,d as ro,T as io,e as co,F as lo,A as uo,W as po,g as go,h as ho}from"./FeatureArchiveDialog-38d9b74d.js";import{S as fo}from"./StrategyItemContainer-7abceb2f.js";import{v as je}from"./v4-a960c1f4.js";function mo(e){return yn("MuiCardContent",e)}Sn("MuiCardContent",["root"]);const yo=["className","component"],So=e=>{const{classes:n}=e;return wn({root:["root"]},mo,n)},bo=u("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),Co=m.forwardRef(function(n,a){const s=bn({props:n,name:"MuiCardContent"}),{className:o,component:i="div"}=s,r=Cn(s,yo),l=gt({},s,{component:i}),d=So(l);return t(bo,gt({as:i,className:vn(d.root,o),ownerState:l,ref:a},r))}),vo=Co,wo=jt(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"),To=jt(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),xo=u("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Ao=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n);return a.name?t(xo,{children:t(Tn,{title:"Event log",feature:n,displayInline:!0})}):null},Eo=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"}})),Ro=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Io=u("div")({display:"flex",alignItems:"center"}),Fo=u("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),ko=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),Ct=u("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),vt=u("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),Do=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n),{project:s,description:o,type:i}=a,r=An(i);return t(Eo,{children:c(Ro,{children:[c(Io,{"data-loading":!0,children:[t(r,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",c(Fo,{children:[xn(i||"")," toggle"]})]}),c(ko,{children:[c(Ct,{"data-loading":!0,children:["Project: ",s]}),t(x,{condition:Boolean(o),show:c(Ct,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(vt,{children:[t("p",{children:o}),t(G,{projectId:e,permission:ue,component:X,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(vt,{children:["No description."," ",t(G,{projectId:e,permission:ue,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(ye,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},wt={lastHourUsage:[],seenApplications:[]},$o=(e,n,a={})=>{const s=async()=>{const g=ve(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(ke("feature metrics"));return h.ok?h.json():wt},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||wt,error:r,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},Bo=e=>({yes:0,no:0,environment:e,timestamp:""}),Po=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||Bo(a.name)),Oo=({enabled:e,className:n})=>{const a=nt(),s=e?"Environment enabled":"Environment disabled",o={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)},i={fill:a.palette.common.white,width:"16px",height:"16px"};return t("div",{style:o,className:n,children:t(To,{style:i,titleAccess:s})})},an=()=>t(re,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Vo=({onRemove:e,onClose:n,isOpen:a})=>t(se,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(an,{})}),_o=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Mo=({onRemove:e,onClose:n,isOpen:a})=>c(se,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(an,{}),t(_o,{children:t(z,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(z,{fontWeight:"bold",children:"Remove strategy"})]}),Lo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=he(),{setToastData:i,setToastApiError:r}=q(),l=fe(),{refetchFeature:d}=N(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),d(),l(zt(e,n))}catch(h){r(L(h))}}},No=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=De(),{refetch:i}=me(e),{setToastData:r,setToastApiError:l}=q();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),r({title:"Changes added to the draft!",type:"success"}),await i()}catch(g){l(L(g))}}},jo=({projectId:e,featureId:n,environmentId:a,strategyId:s,disabled:o,icon:i})=>{const[r,l]=m.useState(!1),{isChangeRequestConfigured:d}=Z(e),p=Lo({featureId:n,projectId:e,strategyId:s,environmentId:a}),g=No({featureId:n,projectId:e,strategyId:s,environmentId:a});return c(V,{children:[t(x,{condition:Boolean(i),show:t(G,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:o,permission:ht,"data-testid":ft,tooltipProps:{title:"Remove strategy"},type:"button",children:t(at,{})}),elseShow:t(oe,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:o,permission:ht,"data-testid":ft,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(x,{condition:d(a),show:t(Mo,{isOpen:r,onClose:()=>l(!1),onRemove:async h=>{await g(h),l(!1)}}),elseShow:t(Vo,{isOpen:r,onClose:()=>l(!1),onRemove:p})})]})},zo=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s));var Wo=En(et,zo);const on=(e,n)=>{const{refetchFeature:a}=N(e,n),s=Rn(e,n),{data:o,error:i,mutate:r}=Wo(["useFeatureImmutable",s],()=>In(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}},ut=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=q(),{addChange:i}=De(),{refetch:r}=me(e),[l,d]=m.useState({isOpen:!1}),p=m.useCallback((T,I,y)=>{d({featureName:n,environment:T,fromEnvironment:y,strategy:I,isOpen:!0})},[]),g=m.useCallback((T,I,y)=>{d({featureName:n,environment:T,fromEnvironment:y,strategies:I,isOpen:!0})},[]),h=m.useCallback(()=>{d({isOpen:!1})},[]),b=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(T){o(L(T)),d({isOpen:!1})}},[i]),v=m.useCallback(async()=>{try{await Promise.all(l.strategies.map(T=>i(e,l.environment,{feature:l.featureName,action:a,payload:T}))),r(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(T){o(L(T)),d({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:v,changeRequestDialogDetails:l}},qo=({payload:e,fromEnvironment:n,environment:a})=>c(z,{children:[c("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Uo=({environmentId:e,environments:n,strategy:a})=>{const s=k("projectId"),o=k("featureId"),[i,r]=m.useState(null),l=Boolean(i),{addStrategyToFeature:d}=he(),{setToastData:p,setToastApiError:g}=q(),{refetchFeature:h}=N(s,o),{refetchFeature:b}=on(s,o),v=()=>{r(null)},T=kn(s),{isChangeRequestConfigured:I}=Z(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:C,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:R}=ut(s,o,"addStrategy"),B=async $=>{const{id:P,...D}={...a,targetEnvironment:$};if(I($)){await w($,{id:P,...D},e);return}try{await d(s,o,$,a),h(),b(),p({title:"Strategy created",text:`Successfully copied a strategy to ${$}`,type:"success"})}catch(U){g(L(U))}v()},O=n.some($=>T(pe,$));return c("div",{children:[t(_e,{isOpen:y.isOpen,onClose:C,environment:y==null?void 0:y.environment,onConfirm:R,messageComponent:t(qo,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(te,{title:`Copy to another environment${O?"":" (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:$=>{r($.currentTarget)},"data-testid":Dn,disabled:!O,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($=>{const P=T(pe,$);return t(te,{title:P?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Pe,{onClick:()=>B($),disabled:!P,children:[t(x,{condition:!P,show:t(Wt,{children:t(qt,{fontSize:"small"})})}),c(ot,{children:["Copy to ",$]})]})})},$)})})]})},sn=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=N(e,a),{setStrategyDisabledState:i}=he(),{setToastData:r,setToastApiError:l}=q(),d=p=>async()=>{try{await i(e,a,n,s.id,!p),r({title:`Strategy ${p?"enabled":"disabled"}`,type:"success"}),o()}catch(g){l(L(g))}};return{onDisable:d(!1),onEnable:d(!0)}},rn=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=De(),{refetch:i}=me(e),{setToastData:r,setToastApiError:l}=q(),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(g){l(L(g))}};return{onSuggestDisable:d(!1),onSuggestEnable:d(!0)}},Ho=({...e})=>{const{projectId:n,environmentId:a}=e,[s,o]=m.useState(!1),{onDisable:i}=sn({...e}),{onSuggestDisable:r}=rn({...e}),{isChangeRequestConfigured:l}=Z(n),d=l(a);return c(V,{children:[t(G,{onClick:()=>o(!0),projectId:n,environmentId:a,permission:nn,tooltipProps:{title:"Disable strategy"},type:"button",children:t(Bn,{})}),t(se,{title:d?"Add disabling strategy to change request?":"Are you sure you want to disable this strategy?",open:s,primaryButtonText:d?"Add to draft":"Disable strategy",secondaryButtonText:"Cancel",onClick:g=>{g.preventDefault(),d?r():i(),o(!1)},onClose:()=>o(!1),children:t(x,{condition:d,show:t(Ut,{environment:a}),elseShow:t(re,{severity:"error",children:"Disabling the strategy will change which users receive access to the feature."})})})]})},Go=({...e})=>{const{projectId:n,environmentId:a}=e,[s,o]=m.useState(!1),{onEnable:i}=sn({...e}),{onSuggestEnable:r}=rn({...e}),{isChangeRequestConfigured:l}=Z(n),d=l(a);return c(V,{children:[t(G,{onClick:()=>o(!0),projectId:n,environmentId:a,permission:nn,tooltipProps:{title:"Enable strategy"},type:"button",children:t(Pn,{})}),t(se,{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:g=>{g.preventDefault(),d?r():i(),o(!1)},onClose:()=>o(!1),children:t(x,{condition:d,show:t(Ut,{environment:a}),elseShow:t(re,{severity:"error",children:"Enabling the strategy will change which users receive access to the feature."})})})]})},Yo=({...e})=>e.strategy.disabled?t(Go,{...e}):t(Ho,{...e}),Ko=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:r})=>{var h;const{uiConfig:l}=Oe(),d=k("projectId"),p=k("featureId"),g=On(d,p,e,n.id);return t(fo,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:c(V,{children:[r,t(x,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(Uo,{environmentId:e,environments:o,strategy:n})}),t(G,{permission:Vn,environmentId:e,projectId:d,component:X,to:g,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(ye,{})}),t(x,{condition:Boolean((h=l==null?void 0:l.flags)==null?void 0:h.strategyDisable),show:()=>t(Yo,{projectId:d,featureId:p,environmentId:e,strategy:n})}),t(jo,{projectId:d,featureId:p,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(_n,{strategy:n})})},Jo=(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)},Xo=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:r,onDragEnd:l})=>{const d=k("projectId"),p=k("featureId"),g=m.useRef(null),h=Jo(d,p,a,e.id);return c(Y,{ref:g,onDragOver:r(g,n),sx:{opacity:o?"0.5":"1"},children:[t(x,{condition:n>0,show:t(Mn,{text:"OR"})}),t(Ko,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(g,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(Qo,{change:h})})]},e.id)},Qo=({change:e})=>{const n=nt();return Ve(n.breakpoints.down("sm"))?null:c(Y,{sx:{mr:1.5},children:[t(x,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Se,{color:"warning",children:"Modified in draft"})}),t(x,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Se,{color:"error",children:"Deleted in draft"})})]})},Zo=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}})),es=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})),cn=({children:e})=>t(Zo,{children:t(es,{children:e})}),ts=({environmentId:e,environments:n,onClick:a})=>{const s=k("projectId"),[o,i]=m.useState(null),r=Boolean(o),{hasAccess:l}=m.useContext(st),d=n.some(p=>l(pe,s,p));return c("div",{children:[t(te,{title:d?"":"(Access denied)",children:t("div",{children:t(ce,{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 g=l(pe,s,p);return t(te,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Pe,{onClick:()=>a(p),disabled:!g,children:[t(x,{condition:!g,show:t(Wt,{children:t(qt,{fontSize:"small"})})}),c(ot,{children:["Copy from ",p]})]})})},p)})})]})},ns=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),as=({payload:e,fromEnvironment:n,environment:a})=>c(ns,{children:[t(z,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>c(z,{children:[c("strong",{children:[we((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),c(z,{children:["from ",n," to ",a]})]}),os=({payload:e,environment:n})=>c(V,{children:[t(z,{component:"span",children:"Add "}),c("strong",{children:[we((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),ss=u(Ln)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),Tt=({title:e,children:n,featureId:a,projectId:s,environmentId:o,strategy:i,Icon:r,onAfterAddStrategy:l})=>{const{addStrategyToFeature:d}=he(),{setToastApiError:p}=q(),{isChangeRequestConfigured:g}=Z(s),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:v,onChangeRequestAddStrategyClose:T}=ut(s,a,"addStrategy");return c(V,{children:[t(ss,{variant:"outlined",children:c(vo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(z,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(z,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(Y,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(oe,{permission:pe,projectId:s,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,i):(await d(s,a,o,i),l())}catch(y){p(L(y))}},children:"Use template"})})]})}),t(_e,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:v,messageComponent:t(os,{environment:o,payload:h.strategy})})]})},rs=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}})),is=u("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),cs=u(rt)(({theme:e})=>({fontWeight:e.fontWeight.bold})),ls=u(X)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),ds=({projectId:e,featureId:n,environmentId:a,strategy:s})=>{const o=Re(s.name),i=we(s.name),r=Za(e,n,a,s.name);return c(ls,{to:r,children:[t(rs,{children:t(o,{})}),c("div",{children:[t(cs,{text:s.displayName||i,maxWidth:"200",maxLength:25}),t(is,{children:s.description})]})]})},us=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=Nn(),o=m.useMemo(()=>s.filter(i=>!i.deprecated),[s]);return t(it,{dense:!0,children:o.map(i=>t(Ie,{children:t(ds,{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=Boolean(r),p=d?"FeatureStrategyMenuPopover":void 0,g=()=>{l(void 0)};return c("div",{onClick:b=>b.stopPropagation(),children:[t(oe,{permission:pe,projectId:n,environmentId:s,onClick:b=>{l(b.currentTarget)},"aria-labelledby":p,variant:o,sx:{minWidth:i?"282px":"auto"},children:e}),t(jn,{id:p,open:d,anchorEl:r,onClose:g,onClick:g,children:t(us,{projectId:n,featureId:a,environmentId:s})})]})},ps=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),gs=u("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),hs=u("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),fs=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=he(),{setToastData:o,setToastApiError:i}=q(),{refetchFeature:r}=N(e,n),{refetchFeature:l}=on(e,n),{feature:d}=N(e,n),p=d==null?void 0:d.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:g}=Z(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:v,onChangeRequestAddStrategyClose:T}=ut(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"})},y=async w=>{var B;const R=((B=p==null?void 0:p.find(O=>O.name===w))==null?void 0:B.strategies)||[];if(g(a)){await b(a,R,w);return}try{await Promise.all(R.map(O=>{const{id:$,...P}={...O,environment:a};return s(e,n,a,P)})),I(!0)}catch(O){i(L(O))}},C=p&&p.length>0;return c(V,{children:[t(_e,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:v,messageComponent:t(as,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(ps,{children:[t(gs,{children:"You have not defined any strategies yet."}),c(hs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Y,{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(x,{condition:C,show:t(ts,{environmentId:a,environments:p.map(w=>w.name),onClick:y})})]}),t(Y,{sx:{width:"100%",mt:3},children:t(cn,{children:"Or use a strategy template"})}),c(Y,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(Tt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:I,Icon:Re("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(Tt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:I,Icon:Re("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:d.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},ms=u("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ys=u("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Ss=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=k("projectId"),o=k("featureId"),{setStrategiesSortOrder:i}=he(),{setToastData:r,setToastApiError:l}=q(),{refetchFeature:d}=N(s,o),[p,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,b]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const v=async C=>{try{await i(s,o,e.name,C),d(),r({title:"Order of strategies updated",type:"success"})}catch(w){l(L(w))}},T=(C,w)=>R=>{var B;b({id:p[w].id,index:w,height:((B=C.current)==null?void 0:B.offsetHeight)||0}),C!=null&&C.current&&(R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/html",C.current.outerHTML),R.dataTransfer.setDragImage(C.current,20,20))},I=C=>(w,R)=>B=>{if(h===null||w.current===null||h.index===R||C===h.id)return;const{top:O,bottom:$}=w.current.getBoundingClientRect(),P=B.clientY-O<h.height,D=$-B.clientY<h.height,U=h.index>R;if(P&&U||D&&!U){const K=[...p],J=K.splice(h.index,1)[0];K.splice(R,0,J),g(K),b({...h,index:R})}},y=()=>{b(null),v(p.map((C,w)=>({id:C.id,sortOrder:w})))};return t(ms,{children:c(ys,{children:[t(x,{condition:p.length>0&&n,show:()=>t(re,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(x,{condition:p.length>0,show:t(V,{children:p.map((C,w)=>t(Xo,{strategy:C,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===C.id,onDragStartRef:T,onDragOver:I(C.id),onDragEnd:y},C.id))}),elseShow:t(fs,{projectId:s,featureId:o,environmentId:e.name})})]})})},ln=(e,n)=>e===0?0:Math.round(n/e*100);var Me={},Le={};Object.defineProperty(Le,"__esModule",{value:!0});Le.defaultOptions=void 0;Le.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 bs(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=bs;function Cs(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}ge.roundTo=Cs;Object.defineProperty(Me,"__esModule",{value:!0});Me.millify=void 0;const ze=Le,xt=ge,At=1e3;function*Et(e){let n=At;for(;;){const a=e/n;if(a<1)return;yield a,n*=At}}function dn(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=xt.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 Et(o))o=v,r+=1;if(r>=s.units.length)return e.toString();let d=xt.roundTo(o,s.precision);for(const v of Et(d))d=v,r+=1;const p=(a=s.units[r])!==null&&a!==void 0?a:"",g=s.lowercase?p.toLowerCase():p,h=s.space?" ":"",b=d.toString().replace(ze.defaultOptions.decimalSeparator,s.decimalSeparator);return`${i}${b}${h}${g}`}Me.millify=dn;var vs=Me.default=dn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=vs(e,{precision:a}),o=!0);const i=t("span",{"data-testid":zn,children:s});return t(x,{condition:o,show:t(te,{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})),un=({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(ae,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(ae,{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(ae,{item:!0,xs:12,sm:4,children:c(We,{children:[t(qe,{children:"Exposure %"}),c(Ue,{children:[ln(e+n,e),"%"]}),c(He,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(ae,{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,"."]})]})})]})},ws=({environmentMetric:e})=>e?c(V,{children:[t(cn,{children:"Feature toggle exposure"}),t("div",{children:t(un,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Rt=u("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),It=u("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ft=u("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),kt=u("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Ts=u(Wn)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),xs=u("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),As=({environmentMetric:e,disabled:n=!1})=>{const a=qn();if(!e)return null;const s=e.yes+e.no,o=ln(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Rt,{children:[c(It,{children:[c(Ft,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),c(kt,{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(Ts,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Rt,{children:[c(It,{children:[c(Ft,{children:[o,"%"]}),c(kt,{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(xs,{"data-loading":!0,children:t(Un,{percentage:o,size:"3rem"})})]})},Es=({strategyName:e})=>{const n=Re(e);return t(te,{title:we(e),arrow:!0,children:t(Rs,{children:t(n,{})})})},Rs=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)}})),Is=({strategies:e})=>e!=null&&e.length?t(Fs,{"aria-label":"Feature strategies",children:e.map(n=>t(ks,{children:t(Es,{strategyName:n.name})},n.id))}):null,Fs=u("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),ks=u("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Ds=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})),$s=u(Hn)({boxShadow:"none",background:"none"}),Bs=u(Gn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Ps=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)}})),Os=u(Ss)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Vs=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})),_s=u("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Ms=u(Oo)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ls=u(rt)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Ns=u("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),js=({env:e})=>{var p;const n=k("projectId"),a=k("featureId"),{metrics:s}=$o(n,a),{feature:o}=N(n,a),{value:i}=Ht(),l=Po(o==null?void 0:o.environments,s).find(g=>g.environment===e.name),d=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(x,{condition:!Boolean(new Set(i.hiddenEnvironments).has(e.name)),show:t(Ds,{enabled:e.enabled,children:c($s,{"data-testid":`${Kn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(Bs,{expandIcon:t(Jn,{titleAccess:"Toggle"}),children:[c(Vs,{"data-loading":!0,enabled:e.enabled,children:[c(_s,{children:[t(Ms,{enabled:e.enabled}),t("div",{children:t(Ls,{text:e.name,maxWidth:"100",maxLength:15})}),t(x,{condition:!e.enabled,show:t(Se,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),c(Ns,{children:[t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(Is,{strategies:d==null?void 0:d.strategies})]})]}),t(As,{environmentMetric:l,disabled:!e.enabled})]}),c(Ps,{enabled:e.enabled,children:[t(Os,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(x,{condition:(((p=d==null?void 0:d.strategies)==null?void 0:p.length)||0)>0,show:c(V,{children:[t(Y,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Qe,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(ws,{environmentMetric:l})]})})]})]})})})},zs=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=N(e,n);if(!a)return null;const{environments:s}=a;return t(V,{children:s==null?void 0:s.map(o=>t(js,{env:o},o.name))})},Ws=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),qs=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Us=({feature:e,header:n})=>{const{locationSettings:a}=Xn();return c(Ws,{children:[n,c("div",{"data-loading":!0,children:[t(qs,{children:"Created at:"}),t("span",{children:Qn(Zn(e.createdAt),a.locale)})]})]})},Hs=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}})),Gs=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Hs,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(x,{condition:n.has(e.name),show:t(ea,{}),elseShow:t(ta,{})})}),Ys=u("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Ks=u("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Js=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:r,enabled:l}=e,d=k("projectId"),p=k("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=Te(),{refetchFeature:b}=N(d,p),{setToastData:v,setToastApiError:T}=q(),{isChangeRequestConfigured:I}=Z(d),{onChangeRequestToggle:y,onChangeRequestToggleClose:C,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:R}=eo(d),B=async()=>{try{await g(d,p,r),v({type:"success",title:`Available in ${r}`,text:`${p} is now available in ${r} based on its defined strategies.`}),b(),n&&n()}catch(D){D instanceof Error&&D.message===no?a():T(L(D))}},O=async()=>{try{await h(d,p,r),v({type:"success",title:`Unavailable in ${r}`,text:`${p} is unavailable in ${r} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(D){T(L(D))}},$=async D=>{if(I(r)){D.preventDefault(),y(p,r,!l);return}if(l){await O();return}await B()},P=c(V,{children:[" ",c("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(rt,{text:r,maxWidth:"120",maxLength:15})]});return c(Ys,{children:[c(Ks,{children:[t(na,{tooltip:l?`Disable feature in ${r}`:`Enable feature in ${r}`,permission:aa,projectId:d,checked:l,onChange:$,environmentId:r}),s??P]}),t(Gs,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i}),t(_e,{isOpen:R.isOpen,onClose:C,environment:R==null?void 0:R.environment,onConfirm:w,messageComponent:t(to,{enabled:R==null?void 0:R.enabled,featureName:R==null?void 0:R.featureName,environment:R.environment})})]})},Xs=u("div")(({theme:e})=>({padding:e.spacing(3)})),Qs=u("div")(()=>({display:"flex",flexDirection:"column"})),Zs=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"})),Dt=u("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),tr=u(ct)(()=>({"&: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 g;return p.enabled&&((g=p.variants)==null?void 0:g.length)});return c(Xs,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const g=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,h=p.variants??[],b=h.length>0&&c(V,{children:[t(Dt,{}),t(te,{title:"View variants",arrow:!0,describeChild:!0,children:t(tr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),v=p.enabled&&h.length===0&&d;return t(Js,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(p.name),i(!0)},children:c(Qs,{children:[t(Zs,{children:p.name}),c(er,{children:[g,b,t(x,{condition:v,show:c(V,{children:[t(Dt,{}),t(ao,{})]})})]})]})},p.name)}),t(oo,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},pn=(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}=oa(Boolean(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})),$t=(e,n)=>e.map(a=>({value:a.title,type:n})),gn=({open:e,setOpen:n})=>{const{tagTypes:a}=sa(),s=k("featureId"),{createTag:o}=so(),{updateFeatureTags:i,loading:r}=Te(),{tags:l,refetch:d,loading:p}=pn(s),{setToastData:g}=q(),[h,b]=m.useState({name:"simple",description:"Simple tag to get you started",icon:""}),v=r||p,[T,I]=m.useState(0),{trackEvent:y}=Gt(),[C,w]=m.useState(Ge(l.filter(f=>f.type===h.name))),{tags:R,refetch:B}=ro(h.name),O=m.useMemo(()=>Ge(R),[R]);m.useEffect(()=>{l&&h&&w(Ge(l.filter(f=>f.type===h.name)))},[JSON.stringify(l),h]);const $=()=>{n(!1),w([])};function P(f,S){const E=f.filter(M=>M.type===h.name).filter(M=>!S.find(j=>M.value===j.value&&M.type===j.type)),_=S.filter(M=>M.type===h.name).filter(M=>!f.find(j=>M.value===j.value&&M.type===j.type));return I(E.length+_.length),{added:E,removed:_}}const D=f=>f.filter(S=>!S.title.startsWith("Create")),U=async(f,S)=>{try{await i(s,{addedTags:f,removedTags:S}),await d()}catch(E){const _=L(E);g({type:"error",title:"Failed to add tag",text:_,confetti:!1})}},K=(f,S)=>{let E="We successfully";return f>0&&(E=E.concat(` added ${f} new tag${f>1?"s":""}`)),f>0&&S>0&&(E=E.concat(" and ")),S>0&&(E=E.concat(` removed ${S} tag${S>1?"s":""}`)),E},J=async f=>{f.preventDefault();const S=$t(D(C),h.name),{added:E,removed:_}=P(S,l);T>0&&(await U(E,_),T>1&&y("suggest_tags",{props:{eventType:"multiple_tags_added"}}),T>0&&g({type:"success",title:`Updated tag${E.length>1?"s":""} to toggle`,text:K(E.length,_.length),confetti:!0})),I(0),w([]),n(!1)},ne=(f,S)=>{S!=null&&typeof S!="string"&&(f.preventDefault(),b(S),w([]),I(0))},ee=(f,S,E)=>{const _=ra(S);E==="selectOption"&&S.forEach((j,H)=>{if(typeof j!="string"&&j.inputValue&&j.inputValue!==""){const xe={value:j.inputValue,type:h.name};o(xe).then(()=>{y("suggest_tags",{props:{eventType:"tag_created"}}),B()}),j.title=j.inputValue,j.inputValue="",_[H]=j}});const M=$t(D(_),h.name);P(M,l),w(_)},A="add-tag-form";return t(se,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:J,disabledPrimaryButton:v||T===0,onClose:$,formId:A,children:c(V,{children:[t(z,{paragraph:!0,sx:{marginBottom:f=>f.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:A,onSubmit:J,children:c(ar,{children:[t(io,{options:a,value:h,onChange:ne}),t(co,{options:O,existingTags:l,tagType:h,selectedOptions:C,onChange:ee})]})})]})})},or=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),sr=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),rr=u(Yt)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ir=u(be)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),cr=u(ce)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),lr=({feature:e,header:n})=>{const{tags:a,refetch:s}=pn(e.name),{deleteTagFromFeature:o}=Te(),[i,r]=m.useState(!1),[l,d]=m.useState(!1),[p,g]=m.useState(),{setToastData:h,setToastApiError:b}=q(),{hasAccess:v}=m.useContext(st),T=v(ue,e.project),I=async()=>{if(p)try{await o(e.name,p.type,p.value),s(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){b(L(y))}};return c(or,{children:[n,t(sr,{children:a.map(y=>{const C=`${y.type}:${y.value}`;return t(rr,{label:C,deleteIcon:t(ia,{titleAccess:"Remove"}),onDelete:T?()=>{d(!0),g(y)}:void 0},C)})}),t(x,{condition:T,show:c(V,{children:[t(x,{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(gn,{open:i,setOpen:r}),c(se,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),g(void 0)},onClick:()=>{d(!1),I(),g(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=k("projectId"),s=k("featureId"),{feature:o}=N(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(Us,{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}=Gt(),{value:n,setValue:a}=Ht(),[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=k("projectId"),a=k("featureId"),s=zt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=pr(),r=()=>e(s);return Kt(a),c(gr,{children:[c("div",{children:[t(Do,{}),t(ur,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(hr,{children:t(zs,{})}),c(Jt,{children:[t(ie,{path:"strategies/create",element:t(Xe,{label:"Create feature strategy",onClose:r,open:!0,children:t(lo,{})})}),t(ie,{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(g=>g.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(Xt,{...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(Qt)(({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(Xt)(()=>({width:"100%"})),wr=({overrides:e,overridesDispatch:n})=>{const{context:a}=lt(),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 h;const d=a.find(({name:b})=>b===r.contextName),p=((h=d==null?void 0:d.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=r.values.filter(b=>p.includes(b));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:b=>n({type:"UPDATE_TYPE_AT",payload:[l,b.target.value]})}),c(br,{children:[t(x,{condition:Boolean(p&&p.length>0),show:t(da,{multiple:!0,id:`override-select-${l}`,isOptionEqualToValue:(b,v)=>b===v,options:p,onChange:i(l),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(vr,{...b,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(te,{title:"Remove",arrow:!0,children:t($e,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:l})},children:t(at,{})})})]})]},`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 Q=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Q||{});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(te)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),hn=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Bt=u(hn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),Rr=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),Ir=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%"}})),Pt=u(Zt)(()=>({width:"100%"})),kr=u("div")(({theme:e})=>({marginLeft:e.spacing(3)})),Dr=u(Zt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),$r=u("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),fn=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(fn)({alignItems:"end",justifyContent:"space-between"}),Pr=u(Qt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),Or=u(ce)(({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:""},Mr=({variant:e,variants:n,updateVariant:a,removeVariant:s,apiPayload:o})=>{const[i,r]=m.useState(e.name),[l,d]=m.useState(e.weightType===Q.FIX),[p,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||_r),[v,T]=xr(e.overrides||[]),{context:I}=lt(),[y,C]=m.useState({}),w=f=>{C(S=>({...S,[f]:void 0}))},R=(f,S)=>{C(E=>({...E,[f]:S}))};m.useEffect(()=>{var f;w("percentage"),(f=o.error)!=null&&f.includes("%")&&R("percentage","Total weight must equal 100%")},[o.error]);const B=!e.new,O=n.filter(({id:f,weightType:S})=>f!==e.id&&S===Q.VARIABLE).length>0,$=f=>{const S=f.weightType===Q.VARIABLE,E=n.some(M=>M.weightType===Q.FIX),_=n.filter(M=>M.weightType===Q.VARIABLE).length===1;return E&&_&&S},P=f=>{w("name"),ne(f,e.id)||R("name","A variant with that name already exists for this environment."),r(f)},D=f=>{(f===""||ee(f))&&g(f)},U=f=>{A(f)||R("payload","Invalid JSON.")},K=()=>{I.length>0&&T({type:"ADD",payload:{contextName:I[0].name,values:[]}})},J=f=>Boolean(f.length),ne=(f,S)=>B||!n.some(E=>E.name===f&&E.id!==S),ee=f=>{if(!l)return!0;if(f===""||f.match(/\.[0-9]{2,}$/))return!1;const S=Number(f);return S>=0&&S<=100},A=f=>{try{return f.type==="json"&&JSON.parse(f.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:i,weight:Number(l?p:100)*10,weightType:l?Q.FIX:Q.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:v.map(f=>({contextName:f.contextName,values:f.values})).filter(f=>f.values&&f.values.length>0),isValid:J(i)&&ne(i,e.id)&&ee(p)&&A(h)&&!o.error})},[i,l,p,h,v]),m.useEffect(()=>{l||g(String(e.weight/10))},[e.weight]),c(Ar,{"data-testid":"VARIANT",children:[t(Er,{arrow:!0,title:$(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:$(e),children:t(at,{})})})}),c(Br,{children:[c($r,{children:[t(hn,{children:"Variant name"}),t(Rr,{children:"This will be used to identify the variant in your code"}),t(Pt,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:Boolean(y.name),errorText:y.name,value:i,onChange:f=>P(f.target.value),disabled:B,required:!0})]}),t(x,{condition:O,show:c(kr,{children:[t(Ir,{label:"Custom percentage",control:t(pa,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:l,onChange:f=>d(f.target.checked)})}),t(Dr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(y.percentage),errorText:y.percentage,value:p,onChange:f=>D(f.target.value),required:l,disabled:!l,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(ga,{position:"end",children:"%"})}})]})})]}),c(Bt,{children:["Payload",t(Je,{tooltip:"Passed along with the the variant object."})]}),c(fn,{children:[t(Pr,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:Vr,onChange:f=>{w("payload"),b(S=>({...S,type:f.target.value}))}}),t(Fr,{children:t(Pt,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:f=>{w("payload"),b(S=>({...S,value:f.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>U(h),error:Boolean(y.payload),errorText:y.payload})})]}),c(Bt,{children:["Overrides",t(Je,{tooltip:"Here you can specify which users should get this variant."})]}),t(wr,{overrides:v,overridesDispatch:T}),t("div",{children:t(Or,{onClick:K,variant:"text",color:"primary","data-testid":"VARIANT_ADD_OVERRIDE_BUTTON",children:"Add override"})})]})},Lr=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(en,{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(re)(({theme:e})=>({marginBottom:e.spacing(2)})),qr=u(re)(({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)})),Ot=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(ce)(({theme:e})=>({marginLeft:e.spacing(3)})),Xr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const r=k("projectId"),l=k("featureId"),{uiConfig:d}=Oe(),{context:p}=lt(),{defaultStickiness:g,loading:h}=fa(r),{isChangeRequestConfigured:b}=Z(r),{data:v}=me(r),{changeRequestInReviewOrApproved:T,alert:I}=Sa(v),y=(e==null?void 0:e.variants)||[],[C,w]=m.useState([]),[R,B]=m.useState();m.useEffect(()=>{h||w(y.length?y.map(F=>({...F,isValid:!0,new:!1,id:je()})):[{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(C==null?void 0:C.length)>0?C[0].stickiness:g,new:!0,isValid:!1,id:je()}])},[n,h]);const O=(F,W)=>{w(le=>mt(le.map(Ae=>Ae.id===W?F:Ae),1e3))},$=()=>{const F=je();w(W=>[...W,{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(W==null?void 0:W.length)>0?W[0].stickiness:g,new:!0,isValid:!1,id:F}]),B(F)};m.useEffect(()=>{if(R){const F=document.getElementById(`variant-name-input-${R}`);F==null||F.scrollIntoView({behavior:"smooth",block:"center"}),F==null||F.focus({preventScroll:!0}),B(void 0)}},[R]);const P=C.map(({new:F,isValid:W,id:le,...Ae})=>Ae),D=s(y,P),U=o(P),K=async F=>{F.preventDefault(),i(P)},J=()=>f?`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(U,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(D.patch,void 0,2)}'`,ne=C.every(({isValid:F})=>F),ee=T((e==null?void 0:e.name)||""),A=ee?"Add to existing change request":"Add change to draft",f=b((e==null?void 0:e.name)||"")&&d.flags.crOnVariants,S=m.useMemo(()=>{var F;return h?"":((F=P[0])==null?void 0:F.stickiness)||g},[h,g,JSON.stringify(P[0]??{})]),E=m.useMemo(()=>["default",...p.filter(F=>F.stickiness).map(F=>F.name)],[p]),_=E.map(F=>({key:F,label:F}));E.includes(S)||_.push({key:S,label:S});const M=async F=>{w(W=>W.map(le=>({...le,stickiness:F})))},j=F=>{M(F)},[H,xe]=m.useState();m.useEffect(()=>{xe(void 0),D.error&&xe(D.error)},[D.error]);const pt=()=>{M(g),a(!1)};return h||S===""?t(ma,{}):t(Xe,{open:n,onClose:pt,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:J,loading:!n,children:[c(Lr,{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(oe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:$,variant:"outlined",permission:de,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(zr,{onSubmit:K,children:[t(x,{condition:ee,show:I,elseShow:t(x,{condition:Boolean(f),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(F=>t(Mr,{variant:F,variants:C,updateVariant:W=>O(W,F.id),removeVariant:()=>w(W=>mt(W.filter(le=>le.id!==F.id),1e3)),projectId:r,apiPayload:D},F.id))}),t(oe,{onClick:$,variant:"outlined",permission:de,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(Gr,{}),t(x,{condition:C.length>0,show:c(V,{children:[t(Hr,{children:t("p",{children:"Stickiness"})}),c(Ot,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(ct,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Yr,{value:S,label:"",editable:!0,onChange:F=>j(F.target.value)})})]}),elseShow:t(Ot,{children:"This environment has no variants. Get started by adding a variant."})}),c(qr,{severity:"error",hidden:!Boolean(H),children:[t("strong",{children:"Error: "}),H]}),c(Kr,{children:[t(ce,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ne,children:f?A:"Save variants"}),t(Jr,{onClick:pt,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(en,{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)})),oi=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),si=({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(x,{condition:s.length>0,show:c(V,{children:[t(ai,{children:t(ba,{variants:s,searchValue:n})}),t(x,{condition:s.length>1,show:c(V,{children:[c(oi,{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(ct,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},ri=u(ot)(({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=Boolean(r),p=e.variants??[];return t(x,{condition:i.length>0&&p.length===0,show:c(V,{children:[t(oe,{onClick:g=>{l(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId: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(g=>t(Pe,{onClick:()=>o(g,e),children:t(ri,{children:`Copy from ${g.name}`})},g.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(ce)(({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=Boolean(i),[d,p]=m.useState([]),g=y=>{p(C=>[...C,y])},h=y=>{p(C=>C.filter(({name:w})=>w!==y.name))},b=y=>{d.includes(y)?h(y):g(y)},v=()=>{p([]),r(null)},T=((I=n.find(y=>y.name===e))==null?void 0:I.variants)??[];return t(x,{condition:T.length>0&&n.length>1,show:c(V,{children:[t(ce,{onClick:y=>{r(y.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(y=>y.name!==e).map(y=>t(ci,{projectId:s,permission:a,environment:y.name,checked:d.includes(y),onClick:()=>b(y)},y.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(re)(({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}=q(),s=nt(),o=Ve(s.breakpoints.down("md")),i=k("projectId"),r=k("featureId"),{feature:l,refetchFeature:d,loading:p}=N(i,r),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=Te(),{refetch:b}=me(i),{addChange:v}=De(),{isChangeRequestConfigured:T}=Z(i),[I,y]=m.useState(""),[C,w]=m.useState(),[R,B]=m.useState(!1),O=m.useMemo(()=>{var A;return((A=l==null?void 0:l.environments)==null?void 0:A.map(f=>({...f,crEnabled:e.flags.crOnVariants&&T(f.name)})))||[]},[l.environments,e.flags.crOnVariants]),$=(A,f)=>xa(A,f),P=(A,f)=>{try{const S=Ta(f,1e3);return{patch:$(A,S)}}catch(S){return{patch:[],error:L(S)}}},D=A=>({feature:r,action:"patchVariant",payload:{variants:A}}),U=async(A,f)=>{if(A.crEnabled)await v(i,A.name,D(f)),b();else{const S=A.variants??[],{patch:E,error:_}=P(S,f);if(E.length===0)return;if(_){n({type:"error",title:_});return}await g(i,r,A.name,E)}d()},K=async(A,f)=>{try{const S=f.filter(({crEnabled:H})=>H),E=f.filter(({crEnabled:H})=>!H);S.length&&await Promise.all(S.map(H=>v(i,H.name,D(A)))),E.length&&await h(i,r,A,E.map(({name:H})=>H)),b(),d();const _=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",M=S.length?`Variants push added to ${S.length===1?`${S[0].name} draft`:`${S.length} drafts`}`:"",j=`${_}${_&&M?". ":""}${M}`;n({title:j,type:"success"})}catch(S){a(L(S))}},J=A=>{w(A),B(!0)},ne=async A=>{if(C)try{await U(C,A),B(!1),n({title:C.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(f){a(L(f))}},ee=async(A,f)=>{try{const S=A.variants??[];await U(f,S),n({title:f.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(S){a(L(S))}};return c(dt,{isLoading:p,header:t(wa,{title:"Variants",actions:t(x,{condition:!o,show:t(V,{children:t(yt,{initialValue:I,onChange:y})})}),children:t(x,{condition:o,show:t(yt,{initialValue:I,onChange:y})})}),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."]}),O.map(A=>{var S;const f=O.filter(({name:E,variants:_})=>E!==A.name&&(_==null?void 0:_.length));return t(si,{environment:A,searchValue:I,children:c(hi,{children:[t(pi,{current:A.name,environments:O,permission:de,projectId:i,onSubmit:E=>K(A.variants??[],E)}),t(ii,{environment:A,permission:de,projectId:i,environmentId:A.name,onCopyVariantsFrom:ee,otherEnvsWithVariants:f}),t(x,{condition:Boolean((S=A.variants)==null?void 0:S.length),show:t(G,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>J(A),permission:de,projectId:i,environmentId:A.name,tooltipProps:{title:"Edit variants"},children:t(ye,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>J(A),variant:"outlined",permission:de,projectId:i,environmentId:A.name,children:"Add variant"})})]})},A.name)}),t(Xr,{environment:C,open:R,setOpen:B,getApiPayload:P,getCrPayload:D,onConfirm:ne})]})},mi=ve("api/admin/client-metrics/features"),mn=(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:Vt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Ra}},Ne.useGlobalFilter,Ne.useSortBy);return Ia([{condition:a,columns:["appName","environment"]}],p,Vt),e.length===0?null:c(Fa,{...o(),rowHeight:"standard",id:n,children:[t(ka,{headerGroups:r}),t(Da,{...i(),children:l.map(g=>(d(g),t($a,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Ba,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Vt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Pa,{icon:t(wo,{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(un,{...n,totalYes:a,totalNo:s})},xi=({metrics:e,hoursBack:n})=>{const a=St(),s=St();return e.length===0?c(Y,{mt:6,children:[t(z,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(z,{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(Y,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Ai,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Y,{mt:4,children:t(Ti,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(Y,{mt:4,children:t(wi,{metrics:e,tableSectionId:s})})]})},Ai=Va.lazy(()=>import("./FeatureMetricsChart-5fc52117.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]},Ri=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ii=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}})),_t=({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(Ri,{children:e}),t(Ii,{children:i.map(r=>t(Fi,{children:t(Yt,{label:r,onClick:o(r),"aria-pressed":r===a,sx:_a})},r))})]})},ki=()=>{const e=k("projectId"),n=k("featureId"),a=Di(e,n),s=$i(n);Kt("Metrics");const[o=Ce,i]=Ei("hoursBack"),{featureMetrics:r}=mn(n,o),[l,d]=m.useState(r);m.useEffect(()=>{r&&d(r)},[r]);const p=Array.from(a)[0],g=Array.from(s)[0],[h=p,b]=Ze("environment"),[v=g,T]=Ze("application"),I=m.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===h).filter(y=>y.appName===v),[l,h,v]);return I?c(dt,{children:[c(ae,{container:!0,component:"header",spacing:2,children:[t(ae,{item:!0,xs:12,md:5,children:t(x,{condition:a.size>0,show:t(_t,{title:"Environments",values:a,value:h,setValue:b})})}),t(ae,{item:!0,xs:12,md:5,children:t(x,{condition:s.size>0,show:t(_t,{title:"Applications",values:s,value:v,setValue:T})})}),t(ae,{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}=N(e,n),s=a.environments.map(o=>o.name);return new Set(s)},$i=e=>{const{featureMetrics:n=[]}=mn(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))},Mt=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Lt=u(re)(({theme:e})=>({marginBottom:e.spacing(1)})),Pi=u(it)({padding:0}),Oi=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const r=k("projectId"),{project:l}=tn(e),{isChangeRequestConfiguredInAnyEnv:d}=Z(e),p=d(),g=m.useMemo(()=>Bi(o.environments.map(b=>b.name),l.environments),[o,l]),h=i?i.length>0:!1;return t(x,{condition:g&&!h&&!p,show:t(se,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(Mt,{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(se,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:c(Mt,{children:[t(Lt,{severity:"warning",children:"Cannot proceed with the move"}),t(x,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(x,{condition:h,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(b=>t(Ie,{children:c(X,{to:`/projects/${r}/change-requests/${b.id}`,children:["View change request"," ",b.id]})},b.id))})]})}),t(x,{condition:p,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(X,{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}=Ma([],ve(`api/admin/projects/${e}/change-requests/pending/${n}`),Vi);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},Mi=()=>{const{hasAccess:e}=m.useContext(st),n=k("projectId"),a=k("featureId"),{feature:s,refetchFeature:o}=N(n,a),[i,r]=m.useState(!1),{changeFeatureProject:l}=Te(),{setToastData:d,setToastApiError:p}=q(),[g,h]=m.useState(n),{projects:b}=La(),v=fe(),{changeRequests:T}=_i(n,a),I=async()=>{try{g&&(await l(n,a,g),o(),d({title:"Project changed",type:"success"}),r(!1),v(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(C){p(L(C))}},y=m.useMemo(()=>b.map(C=>C.id).filter(C=>e(bt,C)),[b,e]);return y.length===0?null:c(V,{children:[t(Na,{value:g,onChange:h,label:"Project",filter:C=>y.includes(C),enabled:!0}),t(oe,{permission:bt,onClick:()=>r(!0),disabled:g===n,projectId:n,children:"Save"}),t(Oi,{changeRequests:T,projectId:g,open:i,feature:s,onClose:()=>r(!1),onClick:I})]})},Li=u("div")({display:"flex",alignItems:"center"}),Ni=u(z)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),ji=({projectId:e,featureId:n})=>{var i;const{feature:a}=N(e,n),s=fe();return c(V,{children:[c(Li,{children:[t(Ni,{children:"Feature information"}),t(G,{permission:ue,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(ye,{})})]}),c(z,{children:["Name: ",t("strong",{children:a.name})]}),c(z,{children:["Description:"," ",t("strong",{children:(i=a.description)!=null&&i.length?a.description:"no description"})]}),c(z,{children:["Type: ",t("strong",{children:a.type})]}),c(z,{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=k("projectId"),n=k("featureId"),[a,s]=m.useState(Ee),{uiConfig:o}=Oe();return t(dt,{header:"Settings",sx:{padding:0},children:c(Y,{sx:{display:"flex"},children:[t(zi,{children:c(it,{children:[t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ee),selected:a===Ee,children:"Metadata"},0),t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ke),selected:a===Ke,hidden:!o.flags.P,children:"Project"},1)]})}),c(Wi,{children:[t(x,{condition:a===Ee,show:t(ji,{projectId:e,featureId:n})}),t(x,{condition:a===Ke&&o.flags.P,show:t(Mi,{})})]})]})})},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"})}),Nt=u("strong")({wordBreak:"break-all"}),Hi=()=>{const e=k("projectId"),n=k("featureId"),{archivedFeatures:a}=ja(),s=za(e,{name:n});return a?a.some(i=>i.name===n)?c("p",{children:["The feature ",t(Nt,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(Nt,{children:n})," does not exist. Would you like to"," ",t(X,{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}})),sc=()=>{const e=k("projectId"),n=k("featureId"),{refetch:a}=tn(e),{favorite:s,unfavorite:o}=qa(),{refetchFeature:i}=N(e,n),[r,l]=m.useState(!1),[d,p]=m.useState(!1),[g,h]=m.useState(!1),b=Ve(`(max-width:${500}px)`),{feature:v,loading:T,error:I,status:y}=N(e,n),C=fe(),{pathname:w}=Ua(),R=Ha(T),B=`/projects/${e}/features/${n}`,O=[{title:"Overview",path:`${B}`,name:"overview"},{title:"Metrics",path:`${B}/metrics`,name:"Metrics"},{title:"Variants",path:`${B}/variants`,name:"Variants"},{title:"Settings",path:`${B}/settings`,name:"Settings"},{title:"Event log",path:`${B}/logs`,name:"Event log"}],$=O.find(D=>D.path===w)??O[0],P=async()=>{v!=null&&v.favorite?await o(e,v.name):await s(e,v.name),i()};return y===404?t(Hi,{}):I!==void 0?t("div",{ref:R}):c("div",{ref:R,children:[c(Gi,{children:[c(Yi,{children:[c(Ki,{children:[t(Ga,{onClick:P,isFavorite:v==null?void 0:v.favorite}),c(Ji,{"data-loading":!0,children:[v.name," "]}),t(x,{condition:!b,show:t(Ui,{stale:v==null?void 0:v.stale})})]}),c(Xi,{children:[t(G,{permission:Ya,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Ka,{})}),t(G,{permission:Ja,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(uo,{})}),t(G,{onClick:()=>h(!0),permission:ue,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(po,{})}),t(G,{onClick:()=>l(!0),permission:ue,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Xa,{})})]})]}),t(Qi,{}),t(Zi,{children:t(Qa,{value:$.path,indicatorColor:"primary",textColor:"primary",children:O.map(D=>t(ec,{label:D.title,value:D.path,onClick:()=>C(D.path),"data-testid":`TAB-${D.title}`},D.title))})})]}),c(Jt,{children:[t(ie,{path:"metrics",element:t(ki,{})}),t(ie,{path:"logs",element:t(Ao,{})}),t(ie,{path:"variants",element:t(fi,{})}),t(ie,{path:"settings",element:t(qi,{})}),t(ie,{path:"*",element:t(fr,{})})]}),t(go,{isOpen:d,onConfirm:()=>{a(),C(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureIds:[n]}),t(ho,{isStale:v.stale,isOpen:g,onClose:()=>{h(!1),i()},featureId:n,projectId:e}),t(gn,{open:r,setOpen:l})]})};export{sc as default};
7
+ --data-raw '${JSON.stringify(D.patch,void 0,2)}'`,ne=C.every(({isValid:F})=>F),ee=T((e==null?void 0:e.name)||""),A=ee?"Add to existing change request":"Add change to draft",f=b((e==null?void 0:e.name)||"")&&d.flags.crOnVariants,S=m.useMemo(()=>{var F;return h?"":((F=P[0])==null?void 0:F.stickiness)||g},[h,g,JSON.stringify(P[0]??{})]),E=m.useMemo(()=>["default",...p.filter(F=>F.stickiness).map(F=>F.name)],[p]),_=E.map(F=>({key:F,label:F}));E.includes(S)||_.push({key:S,label:S});const M=async F=>{w(W=>W.map(le=>({...le,stickiness:F})))},j=F=>{M(F)},[H,xe]=m.useState();m.useEffect(()=>{xe(void 0),D.error&&xe(D.error)},[D.error]);const pt=()=>{M(g),a(!1)};return h||S===""?t(ma,{}):t(Xe,{open:n,onClose:pt,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:J,loading:!n,children:[c(Lr,{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(oe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:$,variant:"outlined",permission:de,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(zr,{onSubmit:K,children:[t(x,{condition:ee,show:I,elseShow:t(x,{condition:Boolean(f),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(F=>t(Mr,{variant:F,variants:C,updateVariant:W=>O(W,F.id),removeVariant:()=>w(W=>mt(W.filter(le=>le.id!==F.id),1e3)),projectId:r,apiPayload:D},F.id))}),t(oe,{onClick:$,variant:"outlined",permission:de,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(Gr,{}),t(x,{condition:C.length>0,show:c(V,{children:[t(Hr,{children:t("p",{children:"Stickiness"})}),c(Ot,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(ct,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Yr,{value:S,label:"",editable:!0,onChange:F=>j(F.target.value)})})]}),elseShow:t(Ot,{children:"This environment has no variants. Get started by adding a variant."})}),c(qr,{severity:"error",hidden:!Boolean(H),children:[t("strong",{children:"Error: "}),H]}),c(Kr,{children:[t(ce,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ne,children:f?A:"Save variants"}),t(Jr,{onClick:pt,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(en,{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)})),oi=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),si=({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(x,{condition:s.length>0,show:c(V,{children:[t(ai,{children:t(ba,{variants:s,searchValue:n})}),t(x,{condition:s.length>1,show:c(V,{children:[c(oi,{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(ct,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},ri=u(ot)(({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=Boolean(r),p=e.variants??[];return t(x,{condition:i.length>0&&p.length===0,show:c(V,{children:[t(oe,{onClick:g=>{l(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId: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(g=>t(Pe,{onClick:()=>o(g,e),children:t(ri,{children:`Copy from ${g.name}`})},g.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(ce)(({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=Boolean(i),[d,p]=m.useState([]),g=y=>{p(C=>[...C,y])},h=y=>{p(C=>C.filter(({name:w})=>w!==y.name))},b=y=>{d.includes(y)?h(y):g(y)},v=()=>{p([]),r(null)},T=((I=n.find(y=>y.name===e))==null?void 0:I.variants)??[];return t(x,{condition:T.length>0&&n.length>1,show:c(V,{children:[t(ce,{onClick:y=>{r(y.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(y=>y.name!==e).map(y=>t(ci,{projectId:s,permission:a,environment:y.name,checked:d.includes(y),onClick:()=>b(y)},y.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(re)(({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}=q(),s=nt(),o=Ve(s.breakpoints.down("md")),i=k("projectId"),r=k("featureId"),{feature:l,refetchFeature:d,loading:p}=N(i,r),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=Te(),{refetch:b}=me(i),{addChange:v}=De(),{isChangeRequestConfigured:T}=Z(i),[I,y]=m.useState(""),[C,w]=m.useState(),[R,B]=m.useState(!1),O=m.useMemo(()=>{var A;return((A=l==null?void 0:l.environments)==null?void 0:A.map(f=>({...f,crEnabled:e.flags.crOnVariants&&T(f.name)})))||[]},[l.environments,e.flags.crOnVariants]),$=(A,f)=>xa(A,f),P=(A,f)=>{try{const S=Ta(f,1e3);return{patch:$(A,S)}}catch(S){return{patch:[],error:L(S)}}},D=A=>({feature:r,action:"patchVariant",payload:{variants:A}}),U=async(A,f)=>{if(A.crEnabled)await v(i,A.name,D(f)),b();else{const S=A.variants??[],{patch:E,error:_}=P(S,f);if(E.length===0)return;if(_){n({type:"error",title:_});return}await g(i,r,A.name,E)}d()},K=async(A,f)=>{try{const S=f.filter(({crEnabled:H})=>H),E=f.filter(({crEnabled:H})=>!H);S.length&&await Promise.all(S.map(H=>v(i,H.name,D(A)))),E.length&&await h(i,r,A,E.map(({name:H})=>H)),b(),d();const _=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",M=S.length?`Variants push added to ${S.length===1?`${S[0].name} draft`:`${S.length} drafts`}`:"",j=`${_}${_&&M?". ":""}${M}`;n({title:j,type:"success"})}catch(S){a(L(S))}},J=A=>{w(A),B(!0)},ne=async A=>{if(C)try{await U(C,A),B(!1),n({title:C.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(f){a(L(f))}},ee=async(A,f)=>{try{const S=A.variants??[];await U(f,S),n({title:f.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(S){a(L(S))}};return c(dt,{isLoading:p,header:t(wa,{title:"Variants",actions:t(x,{condition:!o,show:t(V,{children:t(yt,{initialValue:I,onChange:y})})}),children:t(x,{condition:o,show:t(yt,{initialValue:I,onChange:y})})}),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."]}),O.map(A=>{var S;const f=O.filter(({name:E,variants:_})=>E!==A.name&&(_==null?void 0:_.length));return t(si,{environment:A,searchValue:I,children:c(hi,{children:[t(pi,{current:A.name,environments:O,permission:de,projectId:i,onSubmit:E=>K(A.variants??[],E)}),t(ii,{environment:A,permission:de,projectId:i,environmentId:A.name,onCopyVariantsFrom:ee,otherEnvsWithVariants:f}),t(x,{condition:Boolean((S=A.variants)==null?void 0:S.length),show:t(G,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>J(A),permission:de,projectId:i,environmentId:A.name,tooltipProps:{title:"Edit variants"},children:t(ye,{})}),elseShow:t(oe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>J(A),variant:"outlined",permission:de,projectId:i,environmentId:A.name,children:"Add variant"})})]})},A.name)}),t(Xr,{environment:C,open:R,setOpen:B,getApiPayload:P,getCrPayload:D,onConfirm:ne})]})},mi=ve("api/admin/client-metrics/features"),mn=(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:Vt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Ra}},Ne.useGlobalFilter,Ne.useSortBy);return Ia([{condition:a,columns:["appName","environment"]}],p,Vt),e.length===0?null:c(Fa,{...o(),rowHeight:"standard",id:n,children:[t(ka,{headerGroups:r}),t(Da,{...i(),children:l.map(g=>(d(g),t($a,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Ba,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Vt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Pa,{icon:t(wo,{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(un,{...n,totalYes:a,totalNo:s})},xi=({metrics:e,hoursBack:n})=>{const a=St(),s=St();return e.length===0?c(Y,{mt:6,children:[t(z,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(z,{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(Y,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Ai,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Y,{mt:4,children:t(Ti,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(Y,{mt:4,children:t(wi,{metrics:e,tableSectionId:s})})]})},Ai=Va.lazy(()=>import("./FeatureMetricsChart-a404022d.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]},Ri=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ii=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}})),_t=({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(Ri,{children:e}),t(Ii,{children:i.map(r=>t(Fi,{children:t(Yt,{label:r,onClick:o(r),"aria-pressed":r===a,sx:_a})},r))})]})},ki=()=>{const e=k("projectId"),n=k("featureId"),a=Di(e,n),s=$i(n);Kt("Metrics");const[o=Ce,i]=Ei("hoursBack"),{featureMetrics:r}=mn(n,o),[l,d]=m.useState(r);m.useEffect(()=>{r&&d(r)},[r]);const p=Array.from(a)[0],g=Array.from(s)[0],[h=p,b]=Ze("environment"),[v=g,T]=Ze("application"),I=m.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===h).filter(y=>y.appName===v),[l,h,v]);return I?c(dt,{children:[c(ae,{container:!0,component:"header",spacing:2,children:[t(ae,{item:!0,xs:12,md:5,children:t(x,{condition:a.size>0,show:t(_t,{title:"Environments",values:a,value:h,setValue:b})})}),t(ae,{item:!0,xs:12,md:5,children:t(x,{condition:s.size>0,show:t(_t,{title:"Applications",values:s,value:v,setValue:T})})}),t(ae,{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}=N(e,n),s=a.environments.map(o=>o.name);return new Set(s)},$i=e=>{const{featureMetrics:n=[]}=mn(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))},Mt=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Lt=u(re)(({theme:e})=>({marginBottom:e.spacing(1)})),Pi=u(it)({padding:0}),Oi=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const r=k("projectId"),{project:l}=tn(e),{isChangeRequestConfiguredInAnyEnv:d}=Z(e),p=d(),g=m.useMemo(()=>Bi(o.environments.map(b=>b.name),l.environments),[o,l]),h=i?i.length>0:!1;return t(x,{condition:g&&!h&&!p,show:t(se,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(Mt,{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(se,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:c(Mt,{children:[t(Lt,{severity:"warning",children:"Cannot proceed with the move"}),t(x,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(x,{condition:h,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(b=>t(Ie,{children:c(X,{to:`/projects/${r}/change-requests/${b.id}`,children:["View change request"," ",b.id]})},b.id))})]})}),t(x,{condition:p,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(X,{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}=Ma([],ve(`api/admin/projects/${e}/change-requests/pending/${n}`),Vi);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},Mi=()=>{const{hasAccess:e}=m.useContext(st),n=k("projectId"),a=k("featureId"),{feature:s,refetchFeature:o}=N(n,a),[i,r]=m.useState(!1),{changeFeatureProject:l}=Te(),{setToastData:d,setToastApiError:p}=q(),[g,h]=m.useState(n),{projects:b}=La(),v=fe(),{changeRequests:T}=_i(n,a),I=async()=>{try{g&&(await l(n,a,g),o(),d({title:"Project changed",type:"success"}),r(!1),v(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(C){p(L(C))}},y=m.useMemo(()=>b.map(C=>C.id).filter(C=>e(bt,C)),[b,e]);return y.length===0?null:c(V,{children:[t(Na,{value:g,onChange:h,label:"Project",filter:C=>y.includes(C),enabled:!0}),t(oe,{permission:bt,onClick:()=>r(!0),disabled:g===n,projectId:n,children:"Save"}),t(Oi,{changeRequests:T,projectId:g,open:i,feature:s,onClose:()=>r(!1),onClick:I})]})},Li=u("div")({display:"flex",alignItems:"center"}),Ni=u(z)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),ji=({projectId:e,featureId:n})=>{var i;const{feature:a}=N(e,n),s=fe();return c(V,{children:[c(Li,{children:[t(Ni,{children:"Feature information"}),t(G,{permission:ue,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(ye,{})})]}),c(z,{children:["Name: ",t("strong",{children:a.name})]}),c(z,{children:["Description:"," ",t("strong",{children:(i=a.description)!=null&&i.length?a.description:"no description"})]}),c(z,{children:["Type: ",t("strong",{children:a.type})]}),c(z,{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=k("projectId"),n=k("featureId"),[a,s]=m.useState(Ee),{uiConfig:o}=Oe();return t(dt,{header:"Settings",sx:{padding:0},children:c(Y,{sx:{display:"flex"},children:[t(zi,{children:c(it,{children:[t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ee),selected:a===Ee,children:"Metadata"},0),t(Ie,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Ke),selected:a===Ke,hidden:!o.flags.P,children:"Project"},1)]})}),c(Wi,{children:[t(x,{condition:a===Ee,show:t(ji,{projectId:e,featureId:n})}),t(x,{condition:a===Ke&&o.flags.P,show:t(Mi,{})})]})]})})},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"})}),Nt=u("strong")({wordBreak:"break-all"}),Hi=()=>{const e=k("projectId"),n=k("featureId"),{archivedFeatures:a}=ja(),s=za(e,{name:n});return a?a.some(i=>i.name===n)?c("p",{children:["The feature ",t(Nt,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(Nt,{children:n})," does not exist. Would you like to"," ",t(X,{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}})),sc=()=>{const e=k("projectId"),n=k("featureId"),{refetch:a}=tn(e),{favorite:s,unfavorite:o}=qa(),{refetchFeature:i}=N(e,n),[r,l]=m.useState(!1),[d,p]=m.useState(!1),[g,h]=m.useState(!1),b=Ve(`(max-width:${500}px)`),{feature:v,loading:T,error:I,status:y}=N(e,n),C=fe(),{pathname:w}=Ua(),R=Ha(T),B=`/projects/${e}/features/${n}`,O=[{title:"Overview",path:`${B}`,name:"overview"},{title:"Metrics",path:`${B}/metrics`,name:"Metrics"},{title:"Variants",path:`${B}/variants`,name:"Variants"},{title:"Settings",path:`${B}/settings`,name:"Settings"},{title:"Event log",path:`${B}/logs`,name:"Event log"}],$=O.find(D=>D.path===w)??O[0],P=async()=>{v!=null&&v.favorite?await o(e,v.name):await s(e,v.name),i()};return y===404?t(Hi,{}):I!==void 0?t("div",{ref:R}):c("div",{ref:R,children:[c(Gi,{children:[c(Yi,{children:[c(Ki,{children:[t(Ga,{onClick:P,isFavorite:v==null?void 0:v.favorite}),c(Ji,{"data-loading":!0,children:[v.name," "]}),t(x,{condition:!b,show:t(Ui,{stale:v==null?void 0:v.stale})})]}),c(Xi,{children:[t(G,{permission:Ya,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Ka,{})}),t(G,{permission:Ja,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(uo,{})}),t(G,{onClick:()=>h(!0),permission:ue,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(po,{})}),t(G,{onClick:()=>l(!0),permission:ue,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(Xa,{})})]})]}),t(Qi,{}),t(Zi,{children:t(Qa,{value:$.path,indicatorColor:"primary",textColor:"primary",children:O.map(D=>t(ec,{label:D.title,value:D.path,onClick:()=>C(D.path),"data-testid":`TAB-${D.title}`},D.title))})})]}),c(Jt,{children:[t(ie,{path:"metrics",element:t(ki,{})}),t(ie,{path:"logs",element:t(Ao,{})}),t(ie,{path:"variants",element:t(fi,{})}),t(ie,{path:"settings",element:t(qi,{})}),t(ie,{path:"*",element:t(fr,{})})]}),t(go,{isOpen:d,onConfirm:()=>{a(),C(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureIds:[n]}),t(ho,{isStale:v.stale,isOpen:g,onClose:()=>{h(!1),i()},featureId:n,projectId:e}),t(gn,{open:r,setOpen:l})]})};export{sc as default};