unleash-server 4.22.6 → 4.22.7

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