unleash-server 5.2.2 → 5.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{AdvancedPlayground-0dfff43f.js → AdvancedPlayground-b8d00f81.js} +1 -1
- package/frontend/build/static/{CreateProject-b7f8de7a.js → CreateProject-fe1d0f0f.js} +1 -1
- package/frontend/build/static/{Error-71e2c977.js → Error-6550f020.js} +1 -1
- package/frontend/build/static/{FeatureArchiveDialog-4d2f3953.js → FeatureArchiveDialog-42d2cf92.js} +1 -1
- package/frontend/build/static/{FeatureMetricsChart-e1a34382.js → FeatureMetricsChart-70a6747e.js} +1 -1
- package/frontend/build/static/{FeatureViewLazyExport-3a021f35.js → FeatureViewLazyExport-60874e5e.js} +2 -2
- package/frontend/build/static/{LazyAdminExport-546d2ced.js → LazyAdminExport-c5eec10c.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-6445b527.js → LazyProjectExport-7f66ff80.js} +1 -1
- package/frontend/build/static/{NetworkOverview-c0c2c8df.js → NetworkOverview-b82ebe0c.js} +2 -2
- package/frontend/build/static/{NetworkTraffic-9390e1ed.js → NetworkTraffic-51a825ea.js} +1 -1
- package/frontend/build/static/{Playground-f63ff456.js → Playground-2b482aeb.js} +1 -1
- package/frontend/build/static/{PlaygroundGuidancePopper-b56ef034.js → PlaygroundGuidancePopper-5673aca8.js} +1 -1
- package/frontend/build/static/{RoleCell-1aaafbaa.js → RoleCell-c9b26e7a.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-0c77dc4b.js → StrategyItemContainer-7b356e23.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-21bf4359.js → chartjs-adapter-date-fns.esm-04fda623.js} +1 -1
- package/frontend/build/static/{flowchart-elk-definition-170a3958-a7461fc0.js → flowchart-elk-definition-170a3958-68f1625d.js} +1 -1
- package/frontend/build/static/{index-d3c3fe33.js → index-545ad556.js} +1 -1
- package/frontend/build/static/{index-7bc6399c.js → index-78d048a4.js} +79 -79
- package/frontend/build/static/{index-cd43ec71.js → index-b74e9af8.js} +1 -1
- package/frontend/build/static/{is_dark-59f2cf1b.js → is_dark-77b9ee14.js} +1 -1
- package/frontend/build/static/{mindmap-definition-44684416-4924e603.js → mindmap-definition-44684416-4cca63a5.js} +1 -1
- package/frontend/build/static/{timeline-definition-8e5a9bc6-31a3401d.js → timeline-definition-8e5a9bc6-31dad151.js} +1 -1
- package/frontend/build/static/{unknownify-e3fc74cf.js → unknownify-53fb2d5d.js} +1 -1
- package/frontend/package.json +4 -3
- package/package.json +4 -3
|
@@ -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-
|
|
19
|
+
<script type="module" crossorigin src="/static/index-78d048a4.js"></script>
|
|
20
20
|
<link rel="stylesheet" href="/static/index-66c635eb.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
package/frontend/build/static/{AdvancedPlayground-0dfff43f.js → AdvancedPlayground-b8d00f81.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as B,d as Y,H as G,r as d,j as e,f as C,s as D,g as Z,B as w,V,t as O,v as _,h as g,C as E,F as I,I as he,w as pe,x as ee,T as z,y as fe,c as te,z as ge,u as ne,a as ye,L as Q,e as be,S as ve,i as W,k as xe,A as Se,l as Ce,m as Pe,n as M,D as Re,P as je,o as Ee,p as we,q as Fe}from"./index-7bc6399c.js";import{V as ke,F as se,a as oe,f as K,u as He,r as Te,g as Ae,b as Be,P as Oe,d as Le,c as $e,e as Ue}from"./PlaygroundGuidancePopper-b56ef034.js";import"./StrategyItemContainer-0c77dc4b.js";import"./Error-71e2c977.js";const q=t=>t.charAt(0).toUpperCase()+t.slice(1),Ie=({features:t})=>{const l=B(),n=Y(l.breakpoints.down("sm")),h=Object.keys(t[0].context).map(o=>({Header:q(o),accessor:`context.${o}`,minWidth:160,Cell:G})),m=d.useMemo(()=>[...h,{Header:"Variant",id:"variant",accessor:"variant.name",sortType:"alphanumeric",filterName:"variant",maxWidth:200,Cell:({value:o,row:{original:{variant:i,feature:c,variants:u,isEnabled:v}}})=>e(ke,{variant:i!=null&&i.enabled?o:"",variants:u,feature:c,isEnabled:v})},{id:"isEnabled",Header:"isEnabled",filterName:"isEnabled",accessor:o=>{var i;return o!=null&&o.isEnabled?"true":((i=o==null?void 0:o.strategies)==null?void 0:i.result)==="unknown"?"unknown":"false"},Cell:({row:o})=>e(se,{feature:o.original}),sortType:"playgroundResultState",maxWidth:120,sortInverted:!0},{Header:"",maxWidth:70,id:"info",Cell:({row:o})=>e(oe,{feature:o.original,input:{environment:o.original.environment,context:o.original.context}})}],[]),{headerGroups:y,rows:P,prepareRow:a,setHiddenColumns:R}=C.useTable({columns:m,data:t,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},C.useGlobalFilter,C.useFlexLayout,C.useSortBy);Z([{condition:n,columns:["variant"]}],R,m);const s=d.useRef(null);return e(w,{ref:s,sx:{overflow:"auto",maxHeight:"800px"},children:e(V,{parentRef:s,rows:P,headerGroups:y,prepareRow:a})})},Ne=O("div",{})(({theme:t})=>({flexGrow:0,..._,justifyContent:"flex-start",margin:t.spacing(0,1.5)})),We=O(w)(({theme:t})=>({display:"flex",flexDirection:"row",gap:t.spacing(1)})),Me=({value:t})=>{const l=B(),[n,h]=d.useState(null),m=s=>h(s.currentTarget),y=()=>h(null),P=!!n,a=(t||[]).filter(s=>s.isEnabled),R=(t||[]).filter(s=>!s.isEnabled);return g(Ne,{children:[g(We,{children:[e(E,{condition:a.length>0,show:e(K,{enabled:!0,label:`${a.length}`,showIcon:!0})}),e(E,{condition:R.length>0,show:e(K,{enabled:!1,label:`${R.length}`,showIcon:!0})})]}),g(I,{children:[e(he,{onClick:m,children:e(pe,{})}),g(ee,{open:P,id:`${t}-result-details`,PaperProps:{sx:{borderRadius:`${l.shape.borderRadiusLarge}px`,padding:l.spacing(3)}},onClose:y,anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:-320},children:[e(z,{variant:"subtitle2",sx:{mb:3},children:t[0].environment}),e(Ie,{features:t})]})]})]})},Ge=({features:t})=>{const l=Object.keys(t),n=t[l[0]],h=n[0].context,m=d.useMemo(()=>n.map((c,u)=>({...Object.fromEntries(l.map(v=>[v,t[v][u]]))})),[JSON.stringify(t)]),y=Object.keys(h).map(c=>({Header:q(c),accessor:`${l[0]}.context.${c}`,minWidth:160,Cell:G})),P=l.map(c=>({Header:c,accessor:u=>{var v,p,f;return(v=u[c])!=null&&v.isEnabled?"true":((f=(p=u[c])==null?void 0:p.strategies)==null?void 0:f.result)==="unknown"?"unknown":"false"},Cell:({row:u})=>g(w,{sx:{display:"flex"},children:[e(se,{feature:u.original[c]}),e(oe,{feature:u.original[c],input:{environment:u.original[c].environment,context:u.original[c].context}})]}),sortType:"playgroundResultState",maxWidth:140})),a=d.useMemo(()=>[...y,...P],[]),{headerGroups:R,rows:s,prepareRow:o}=C.useTable({columns:a,data:m,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},C.useGlobalFilter,C.useFlexLayout,C.useSortBy),i=d.useRef(null);return e(w,{ref:i,sx:{overflow:"auto",maxHeight:"800px"},children:e(V,{parentRef:i,rows:s,headerGroups:R,prepareRow:o})})},De=O("div",{})(({theme:t})=>({flexGrow:0,..._,justifyContent:"flex-start",margin:t.spacing(0,1.5)})),Ve=O(fe)(({theme:t})=>({textAlign:"left",textDecorationStyle:"dotted",textUnderlineOffset:t.spacing(.75),color:t.palette.neutral.dark})),ze=({value:t})=>{const l=B(),[n,h]=d.useState(null),m=a=>h(a.currentTarget),y=()=>h(null);return e(De,{children:g(I,{children:[e(Ve,{variant:"body2",onClick:m,children:"Preview diff"}),g(ee,{open:!!n,id:`${t}-result-details`,PaperProps:{sx:{borderRadius:`${l.shape.borderRadiusLarge}px`,padding:l.spacing(3)}},onClose:y,anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:-320},children:[e(z,{variant:"subtitle2",sx:{mb:3},children:"Environments diff"}),e(Ge,{features:t})]})]})})},qe=t=>t.reduce((l,n)=>l+Object.values(n.environments).flatMap(h=>Object.keys(h)).length,0),Je={id:"name"},{value:X,setValue:Qe}=te("AdvancedPlaygroundResultsTable:v1",Je),Ke=({features:t,input:l,loading:n})=>{const{trackEvent:h}=ge();t&&h("playground",{props:{eventType:"number-of-combinations",count:qe(t)}});const[m,y]=ne(),P=ye(n),[a,R]=d.useState(m.get("search")||""),s=B(),o=Y(s.breakpoints.down("md")),i=t&&t.length>0?Object.keys(t[0].environments).length:0,c=d.useMemo(()=>{var S;return[{Header:"Name",accessor:"name",searchable:!0,minWidth:160,Cell:({value:b,row:{original:k}})=>e(Q,{title:b,to:`/projects/${k==null?void 0:k.projectId}/features/${b}`})},{Header:"Project ID",accessor:"projectId",sortType:"alphanumeric",filterName:"projectId",searchable:!0,minWidth:150,Cell:({value:b})=>e(Q,{title:b,to:`/projects/${b}`})},...((S=l==null?void 0:l.environments)==null?void 0:S.map(b=>({Header:n?()=>"":q(b),maxWidth:140,id:`environments.${b}`,align:"flex-start",Cell:({row:k})=>e(Me,{value:k.original.environments[b]})})))||[],...i>1?[{Header:"Diff",minWidth:150,id:"diff",align:"left",Cell:({row:b})=>e(ze,{value:b.original.environments})}]:[]]},[l]),{data:u,getSearchText:v,getSearchContext:p}=be(c,a,t||[]),f=d.useMemo(()=>n?Array(5).fill({name:"Feature name",projectId:"Feature Project",environments:{name:"Feature Environments",variants:[]},enabled:!0}):u,[u,n]),[T]=d.useState(()=>({sortBy:[{id:m.get("sort")||X.id,desc:m.has("order")?m.get("order")==="desc":X.desc}]})),{headerGroups:x,rows:A,state:{sortBy:F},prepareRow:N,setHiddenColumns:L}=C.useTable({initialState:T,columns:c,data:f,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:G}},C.useGlobalFilter,C.useFlexLayout,C.useSortBy);return Z([{condition:o,columns:["projectId"]}],L,c),d.useEffect(()=>{if(n)return;const S=Object.fromEntries(m);S.sort=F[0].id,F[0].desc?S.order="desc":S.order&&delete S.order,a?S.search=a:delete S.search,y(S,{replace:!0}),Qe({id:F[0].id,desc:F[0].desc||!1})},[n,F,a]),g(I,{children:[g(w,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[e(z,{variant:"subtitle1",sx:{ml:1},children:t!==void 0&&!n?`Results (${A.length<f.length?`${A.length} of ${f.length}`:f.length})`:"Results"}),e(ve,{initialValue:a,onChange:R,hasFilters:!0,getSearchContext:p,disabled:n,containerStyles:{marginLeft:"1rem",maxWidth:"400px"}})]}),e(E,{condition:!n&&!f,show:()=>e(W,{children:f===void 0?"None of the feature toggles were evaluated yet.":"No results found."}),elseShow:()=>g(w,{ref:P,sx:{overflow:"auto"},children:[e(xe,{value:v(a),children:e(V,{rows:A,headerGroups:x,prepareRow:N})}),e(E,{condition:f.length===0&&(a==null?void 0:a.length)>0,show:g(W,{children:["No feature toggles found matching “",a,"”"]})}),e(E,{condition:f&&f.length===0&&!a,show:e(W,{children:"No features toggles to display"})})]})})]})},Xe=O(Se)(({theme:t})=>({marginBottom:t.spacing(3)})),tt=({FormComponent:t=$e})=>{const l={projects:[],environments:[]},{value:n,setValue:h}=te("AdvancedPlayground:v1",l),{environments:m}=Ce(),y=B(),P=!0,[a,R]=d.useState(),[s,o]=d.useState(n.environments),[i,c]=d.useState(n.projects),[u,v]=d.useState(n.context),[p,f]=d.useState(),{setToastData:T}=Pe(),[x,A]=ne(),F=Array.from(x.entries()).length,{evaluateAdvancedPlayground:N,loading:L}=He(),[S,b]=d.useState(!1);d.useEffect(()=>{(s==null?void 0:s.length)===0&&o([Te(m)])},[JSON.stringify(s),JSON.stringify(m)]),d.useEffect(()=>{F>0&&k()},[]);const k=()=>{try{const r=re(),j=ae(),$=le();(async()=>{r&&$&&await J(r||[],j||"*",$)})()}catch(r){T({type:"error",title:`Failed to parse URL parameters: ${M(r)}`})}},re=()=>{let r=null;const j=x.get("environments");return j&&(r=j.split(","),o(r)),r},ae=()=>{let r=null,j=x.get("projects");return j&&(r=j.split(","),c(r)),r},le=()=>{let r=x.get("context");return r&&(r=decodeURI(r),v(r)),r},J=async(r,j,$,U)=>{try{R(void 0);const H=JSON.parse($||"{}"),me=await N({environments:Ae(r),projects:Be(j),context:{appName:"playground",...H}});U&&typeof U=="function"&&U(),f(me)}catch(H){H instanceof Re?R(H.message):H instanceof SyntaxError?T({type:"error",title:`Error parsing context: ${M(H)}`}):T({type:"error",title:M(H)})}},ie=async r=>{r.preventDefault(),b(!0),await J(s,i,u,()=>{ce(),h({environments:s,projects:i,context:u})})},ce=()=>{x.set("context",encodeURI(u||"")),Array.isArray(s)&&s.length>0&&!(s.length===1&&s[0]==="*")?x.set("environments",s.join(",")):x.delete("projects"),Array.isArray(i)&&i.length>0&&!(i.length===1&&i[0]==="*")?x.set("projects",i.join(",")):x.delete("projects"),A(x)},de=p&&!P?"35%":"auto",ue=Ue(P,p);return e(je,{header:e(Ee,{title:"Unleash playground",actions:e(Oe,{})}),disableLoading:!0,bodyClass:"no-padding",children:g(w,{sx:{display:"flex",flexDirection:"column"},children:[e(w,{sx:{background:y.palette.background.elevation2,borderBottomLeftRadius:y.shape.borderRadiusMedium},children:e(we,{elevation:0,sx:{px:4,py:3,mb:4,mt:2,background:y.palette.background.elevation2,transition:"width 0.4s ease",minWidth:"auto",width:de,position:"sticky",top:0},children:e(t,{onSubmit:ie,context:u,setContext:v,availableEnvironments:m,projects:i,environments:s,setProjects:c,setEnvironments:o})})}),g(w,{sx:r=>({width:ue,transition:"width 0.4s ease",padding:r.spacing(4,2)}),children:[e(E,{condition:!!a,show:e(Xe,{severity:"warning",children:a})}),e(E,{condition:L,show:e(Fe,{}),elseShow:g(I,{children:[e(E,{condition:!!p,show:e(Ke,{loading:L,features:p==null?void 0:p.features,input:p==null?void 0:p.input})}),e(E,{condition:!p&&!S,show:e(Le,{})})]})})]})]})})};export{tt as AdvancedPlayground,tt as default};
|
|
1
|
+
import{b as B,d as Y,H as G,r as d,j as e,f as C,s as D,g as Z,B as w,V,t as O,v as _,h as g,C as E,F as I,I as he,w as pe,x as ee,T as z,y as fe,c as te,z as ge,u as ne,a as ye,L as Q,e as be,S as ve,i as W,k as xe,A as Se,l as Ce,m as Pe,n as M,D as Re,P as je,o as Ee,p as we,q as Fe}from"./index-78d048a4.js";import{V as ke,F as se,a as oe,f as K,u as He,r as Te,g as Ae,b as Be,P as Oe,d as Le,c as $e,e as Ue}from"./PlaygroundGuidancePopper-5673aca8.js";import"./StrategyItemContainer-7b356e23.js";import"./Error-6550f020.js";const q=t=>t.charAt(0).toUpperCase()+t.slice(1),Ie=({features:t})=>{const l=B(),n=Y(l.breakpoints.down("sm")),h=Object.keys(t[0].context).map(o=>({Header:q(o),accessor:`context.${o}`,minWidth:160,Cell:G})),m=d.useMemo(()=>[...h,{Header:"Variant",id:"variant",accessor:"variant.name",sortType:"alphanumeric",filterName:"variant",maxWidth:200,Cell:({value:o,row:{original:{variant:i,feature:c,variants:u,isEnabled:v}}})=>e(ke,{variant:i!=null&&i.enabled?o:"",variants:u,feature:c,isEnabled:v})},{id:"isEnabled",Header:"isEnabled",filterName:"isEnabled",accessor:o=>{var i;return o!=null&&o.isEnabled?"true":((i=o==null?void 0:o.strategies)==null?void 0:i.result)==="unknown"?"unknown":"false"},Cell:({row:o})=>e(se,{feature:o.original}),sortType:"playgroundResultState",maxWidth:120,sortInverted:!0},{Header:"",maxWidth:70,id:"info",Cell:({row:o})=>e(oe,{feature:o.original,input:{environment:o.original.environment,context:o.original.context}})}],[]),{headerGroups:y,rows:P,prepareRow:a,setHiddenColumns:R}=C.useTable({columns:m,data:t,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},C.useGlobalFilter,C.useFlexLayout,C.useSortBy);Z([{condition:n,columns:["variant"]}],R,m);const s=d.useRef(null);return e(w,{ref:s,sx:{overflow:"auto",maxHeight:"800px"},children:e(V,{parentRef:s,rows:P,headerGroups:y,prepareRow:a})})},Ne=O("div",{})(({theme:t})=>({flexGrow:0,..._,justifyContent:"flex-start",margin:t.spacing(0,1.5)})),We=O(w)(({theme:t})=>({display:"flex",flexDirection:"row",gap:t.spacing(1)})),Me=({value:t})=>{const l=B(),[n,h]=d.useState(null),m=s=>h(s.currentTarget),y=()=>h(null),P=!!n,a=(t||[]).filter(s=>s.isEnabled),R=(t||[]).filter(s=>!s.isEnabled);return g(Ne,{children:[g(We,{children:[e(E,{condition:a.length>0,show:e(K,{enabled:!0,label:`${a.length}`,showIcon:!0})}),e(E,{condition:R.length>0,show:e(K,{enabled:!1,label:`${R.length}`,showIcon:!0})})]}),g(I,{children:[e(he,{onClick:m,children:e(pe,{})}),g(ee,{open:P,id:`${t}-result-details`,PaperProps:{sx:{borderRadius:`${l.shape.borderRadiusLarge}px`,padding:l.spacing(3)}},onClose:y,anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:-320},children:[e(z,{variant:"subtitle2",sx:{mb:3},children:t[0].environment}),e(Ie,{features:t})]})]})]})},Ge=({features:t})=>{const l=Object.keys(t),n=t[l[0]],h=n[0].context,m=d.useMemo(()=>n.map((c,u)=>({...Object.fromEntries(l.map(v=>[v,t[v][u]]))})),[JSON.stringify(t)]),y=Object.keys(h).map(c=>({Header:q(c),accessor:`${l[0]}.context.${c}`,minWidth:160,Cell:G})),P=l.map(c=>({Header:c,accessor:u=>{var v,p,f;return(v=u[c])!=null&&v.isEnabled?"true":((f=(p=u[c])==null?void 0:p.strategies)==null?void 0:f.result)==="unknown"?"unknown":"false"},Cell:({row:u})=>g(w,{sx:{display:"flex"},children:[e(se,{feature:u.original[c]}),e(oe,{feature:u.original[c],input:{environment:u.original[c].environment,context:u.original[c].context}})]}),sortType:"playgroundResultState",maxWidth:140})),a=d.useMemo(()=>[...y,...P],[]),{headerGroups:R,rows:s,prepareRow:o}=C.useTable({columns:a,data:m,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},C.useGlobalFilter,C.useFlexLayout,C.useSortBy),i=d.useRef(null);return e(w,{ref:i,sx:{overflow:"auto",maxHeight:"800px"},children:e(V,{parentRef:i,rows:s,headerGroups:R,prepareRow:o})})},De=O("div",{})(({theme:t})=>({flexGrow:0,..._,justifyContent:"flex-start",margin:t.spacing(0,1.5)})),Ve=O(fe)(({theme:t})=>({textAlign:"left",textDecorationStyle:"dotted",textUnderlineOffset:t.spacing(.75),color:t.palette.neutral.dark})),ze=({value:t})=>{const l=B(),[n,h]=d.useState(null),m=a=>h(a.currentTarget),y=()=>h(null);return e(De,{children:g(I,{children:[e(Ve,{variant:"body2",onClick:m,children:"Preview diff"}),g(ee,{open:!!n,id:`${t}-result-details`,PaperProps:{sx:{borderRadius:`${l.shape.borderRadiusLarge}px`,padding:l.spacing(3)}},onClose:y,anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:-320},children:[e(z,{variant:"subtitle2",sx:{mb:3},children:"Environments diff"}),e(Ge,{features:t})]})]})})},qe=t=>t.reduce((l,n)=>l+Object.values(n.environments).flatMap(h=>Object.keys(h)).length,0),Je={id:"name"},{value:X,setValue:Qe}=te("AdvancedPlaygroundResultsTable:v1",Je),Ke=({features:t,input:l,loading:n})=>{const{trackEvent:h}=ge();t&&h("playground",{props:{eventType:"number-of-combinations",count:qe(t)}});const[m,y]=ne(),P=ye(n),[a,R]=d.useState(m.get("search")||""),s=B(),o=Y(s.breakpoints.down("md")),i=t&&t.length>0?Object.keys(t[0].environments).length:0,c=d.useMemo(()=>{var S;return[{Header:"Name",accessor:"name",searchable:!0,minWidth:160,Cell:({value:b,row:{original:k}})=>e(Q,{title:b,to:`/projects/${k==null?void 0:k.projectId}/features/${b}`})},{Header:"Project ID",accessor:"projectId",sortType:"alphanumeric",filterName:"projectId",searchable:!0,minWidth:150,Cell:({value:b})=>e(Q,{title:b,to:`/projects/${b}`})},...((S=l==null?void 0:l.environments)==null?void 0:S.map(b=>({Header:n?()=>"":q(b),maxWidth:140,id:`environments.${b}`,align:"flex-start",Cell:({row:k})=>e(Me,{value:k.original.environments[b]})})))||[],...i>1?[{Header:"Diff",minWidth:150,id:"diff",align:"left",Cell:({row:b})=>e(ze,{value:b.original.environments})}]:[]]},[l]),{data:u,getSearchText:v,getSearchContext:p}=be(c,a,t||[]),f=d.useMemo(()=>n?Array(5).fill({name:"Feature name",projectId:"Feature Project",environments:{name:"Feature Environments",variants:[]},enabled:!0}):u,[u,n]),[T]=d.useState(()=>({sortBy:[{id:m.get("sort")||X.id,desc:m.has("order")?m.get("order")==="desc":X.desc}]})),{headerGroups:x,rows:A,state:{sortBy:F},prepareRow:N,setHiddenColumns:L}=C.useTable({initialState:T,columns:c,data:f,sortTypes:D,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:G}},C.useGlobalFilter,C.useFlexLayout,C.useSortBy);return Z([{condition:o,columns:["projectId"]}],L,c),d.useEffect(()=>{if(n)return;const S=Object.fromEntries(m);S.sort=F[0].id,F[0].desc?S.order="desc":S.order&&delete S.order,a?S.search=a:delete S.search,y(S,{replace:!0}),Qe({id:F[0].id,desc:F[0].desc||!1})},[n,F,a]),g(I,{children:[g(w,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[e(z,{variant:"subtitle1",sx:{ml:1},children:t!==void 0&&!n?`Results (${A.length<f.length?`${A.length} of ${f.length}`:f.length})`:"Results"}),e(ve,{initialValue:a,onChange:R,hasFilters:!0,getSearchContext:p,disabled:n,containerStyles:{marginLeft:"1rem",maxWidth:"400px"}})]}),e(E,{condition:!n&&!f,show:()=>e(W,{children:f===void 0?"None of the feature toggles were evaluated yet.":"No results found."}),elseShow:()=>g(w,{ref:P,sx:{overflow:"auto"},children:[e(xe,{value:v(a),children:e(V,{rows:A,headerGroups:x,prepareRow:N})}),e(E,{condition:f.length===0&&(a==null?void 0:a.length)>0,show:g(W,{children:["No feature toggles found matching “",a,"”"]})}),e(E,{condition:f&&f.length===0&&!a,show:e(W,{children:"No features toggles to display"})})]})})]})},Xe=O(Se)(({theme:t})=>({marginBottom:t.spacing(3)})),tt=({FormComponent:t=$e})=>{const l={projects:[],environments:[]},{value:n,setValue:h}=te("AdvancedPlayground:v1",l),{environments:m}=Ce(),y=B(),P=!0,[a,R]=d.useState(),[s,o]=d.useState(n.environments),[i,c]=d.useState(n.projects),[u,v]=d.useState(n.context),[p,f]=d.useState(),{setToastData:T}=Pe(),[x,A]=ne(),F=Array.from(x.entries()).length,{evaluateAdvancedPlayground:N,loading:L}=He(),[S,b]=d.useState(!1);d.useEffect(()=>{(s==null?void 0:s.length)===0&&o([Te(m)])},[JSON.stringify(s),JSON.stringify(m)]),d.useEffect(()=>{F>0&&k()},[]);const k=()=>{try{const r=re(),j=ae(),$=le();(async()=>{r&&$&&await J(r||[],j||"*",$)})()}catch(r){T({type:"error",title:`Failed to parse URL parameters: ${M(r)}`})}},re=()=>{let r=null;const j=x.get("environments");return j&&(r=j.split(","),o(r)),r},ae=()=>{let r=null,j=x.get("projects");return j&&(r=j.split(","),c(r)),r},le=()=>{let r=x.get("context");return r&&(r=decodeURI(r),v(r)),r},J=async(r,j,$,U)=>{try{R(void 0);const H=JSON.parse($||"{}"),me=await N({environments:Ae(r),projects:Be(j),context:{appName:"playground",...H}});U&&typeof U=="function"&&U(),f(me)}catch(H){H instanceof Re?R(H.message):H instanceof SyntaxError?T({type:"error",title:`Error parsing context: ${M(H)}`}):T({type:"error",title:M(H)})}},ie=async r=>{r.preventDefault(),b(!0),await J(s,i,u,()=>{ce(),h({environments:s,projects:i,context:u})})},ce=()=>{x.set("context",encodeURI(u||"")),Array.isArray(s)&&s.length>0&&!(s.length===1&&s[0]==="*")?x.set("environments",s.join(",")):x.delete("projects"),Array.isArray(i)&&i.length>0&&!(i.length===1&&i[0]==="*")?x.set("projects",i.join(",")):x.delete("projects"),A(x)},de=p&&!P?"35%":"auto",ue=Ue(P,p);return e(je,{header:e(Ee,{title:"Unleash playground",actions:e(Oe,{})}),disableLoading:!0,bodyClass:"no-padding",children:g(w,{sx:{display:"flex",flexDirection:"column"},children:[e(w,{sx:{background:y.palette.background.elevation2,borderBottomLeftRadius:y.shape.borderRadiusMedium},children:e(we,{elevation:0,sx:{px:4,py:3,mb:4,mt:2,background:y.palette.background.elevation2,transition:"width 0.4s ease",minWidth:"auto",width:de,position:"sticky",top:0},children:e(t,{onSubmit:ie,context:u,setContext:v,availableEnvironments:m,projects:i,environments:s,setProjects:c,setEnvironments:o})})}),g(w,{sx:r=>({width:ue,transition:"width 0.4s ease",padding:r.spacing(4,2)}),children:[e(E,{condition:!!a,show:e(Xe,{severity:"warning",children:a})}),e(E,{condition:L,show:e(Fe,{}),elseShow:g(I,{children:[e(E,{condition:!!p,show:e(Ke,{loading:L,features:p==null?void 0:p.features,input:p==null?void 0:p.input})}),e(E,{condition:!p&&!S,show:e(Le,{})})]})})]})]})})};export{tt as AdvancedPlayground,tt as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{m as k,ar as R,a6 as w,as as O,z 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,n as z,aA as K}from"./index-
|
|
1
|
+
import{m as k,ar as R,a6 as w,as as O,z 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,n as z,aA as K}from"./index-78d048a4.js";const $="CREATE_PROJECT_BTN",H=()=>{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(z(I))}}},handleCancel:()=>{t(K)},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":$})})})};export{H as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as r,j as o}from"./index-
|
|
1
|
+
import{E as r,j as o}from"./index-78d048a4.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};
|
package/frontend/build/static/{FeatureArchiveDialog-4d2f3953.js → FeatureArchiveDialog-42d2cf92.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{E as ie,j as r,b as ce,aI as Y,a_ as Z,h as C,bb as W,C as U,A as we,T as O,ca as Ae,t as j,fx as xe,bh as Re,fy as X,as as J,a6 as ee,fz as ke,fA as Fe,fB as De,fC as Pe,bv as G,fD as $e,ai as Oe,fE as Be,fF as N,cl as le,r as w,au as ue,m as z,fG as de,z as ge,fH as he,av as fe,a$ as pe,br as qe,fI as _e,n as B,dp as Le,b0 as Ue,aZ as me,aJ as Q,b2 as ye,fJ as je,fK as Ve,fL as Ie,fM as ze,fN as Ye,fO as We,b3 as be,bc as He,fP as Me,F as K,aN as ne,B as Ge,v as Je,bR as te,fQ as Ke,ej as Ne,fR as Qe,fS as Ze,fT as Xe,be as et,bf as tt,bg as at,am as Se,al as ve,bU as st,cc as nt,df as rt,$ as ot,fU as it,de as ct,a8 as lt,bP as ut,aU as dt,aS as gt,aT as ht}from"./index-
|
|
1
|
+
import{E as ie,j as r,b as ce,aI as Y,a_ as Z,h as C,bb as W,C as U,A as we,T as O,ca as Ae,t as j,fx as xe,bh as Re,fy as X,as as J,a6 as ee,fz as ke,fA as Fe,fB as De,fC as Pe,bv as G,fD as $e,ai as Oe,fE as Be,fF as N,cl as le,r as w,au as ue,m as z,fG as de,z as ge,fH as he,av as fe,a$ as pe,br as qe,fI as _e,n as B,dp as Le,b0 as Ue,aZ as me,aJ as Q,b2 as ye,fJ as je,fK as Ve,fL as Ie,fM as ze,fN as Ye,fO as We,b3 as be,bc as He,fP as Me,F as K,aN as ne,B as Ge,v as Je,bR as te,fQ as Ke,ej as Ne,fR as Qe,fS as Ze,fT as Xe,be as et,bf as tt,bg as at,am as Se,al as ve,bU as st,cc as nt,df as rt,$ as ot,fU as it,de as ct,a8 as lt,bP as ut,aU as dt,aS as gt,aT as ht}from"./index-78d048a4.js";const ft=ie(r("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"),zt=ie(r("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"),Yt=({enabled:e,className:s})=>{const t=ce(),i=e?"Environment enabled":"Environment disabled",a={backgroundColor:e?t.palette.primary.light:t.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:t.spacing(1)},n={fill:t.palette.common.white,width:"16px",height:"16px"};return r("div",{style:a,className:s,children:r(ft,{style:n,titleAccess:i})})},pt=({isOpen:e,onConfirm:s,onClose:t,showBanner:i,environment:a,messageComponent:n})=>{const o=Y("projectId"),{data:d}=Z(o),{changeRequestInReviewOrApproved:f,alert:h}=Ae(d),l=f(a||"");return C(W,{open:e,primaryButtonText:l?"Add to existing change request":"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:s,onClose:t,title:"Request changes",fullWidth:!0,children:[r(U,{condition:l,show:h}),r(U,{condition:!!i,show:C(we,{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."]})}),r(O,{variant:"body2",color:"text.secondary",children:"Your suggestion:"}),n]})},mt=(e,s)=>{const t={};return s.parameters.forEach(i=>{t[i.name]=yt(e,i)}),{name:s.name,constraints:[],parameters:t}},yt=(e,s)=>s.name==="rollout"||s.name==="percentage"||s.type==="percentage"?"50":s.name==="stickiness"?"":s.name==="groupId"?e:s.type==="boolean"?"false":"",bt=j("form")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),re=j("hr")(({theme:e})=>({width:"100%",height:"1px",margin:e.spacing(2,0),border:"none",background:e.palette.background.elevation2})),St=j("div")(({theme:e})=>({display:"flex",justifyContent:"end",gap:e.spacing(2),paddingBottom:e.spacing(10)})),vt=({projectId:e,environmentId:s,permission:t,onSubmit:i,onCancel:a,loading:n,strategy:o,setStrategy:d,segments:f,setSegments:h,errors:l})=>{const S=xe(o.constraints),c=Re(t,e,s),{strategyDefinition:u}=X(o==null?void 0:o.name),m=J(),{uiConfig:g,error:v,loading:x}=ee();if(v)throw v;if(x||!u)return null;const D=p=>u.parameters.find(E=>E.name===p),A=(p,E)=>{const F=D(p);if(p!=="groupId"){const T=Be(F,E);return T?(l.setFormError(p,T),!1):(l.removeFormError(p),!0)}return!0},y=()=>u.parameters.map(p=>p.name).map(p=>{var E;return A(p,(E=o.parameters)==null?void 0:E[p])}).every(Boolean),q=()=>{m(`/projects/${e}/settings/default-strategy`)};return C(bt,{onSubmit:async p=>{if(p.preventDefault(),y())i();else return},children:[r(ke,{title:o.title||"",setTitle:p=>{d(E=>({...E,title:p}))}}),r(U,{condition:!!g.flags.SE,show:r(Fe,{segments:f,setSegments:h,projectId:e})}),r(De,{projectId:e,environmentId:s,strategy:o,setStrategy:d}),r(re,{}),r(Pe,{strategy:o,strategyDefinition:u,setStrategy:d,validateParameter:A,errors:l,hasAccess:c}),r(re,{}),C(St,{children:[r(G,{permission:t,projectId:e,environmentId:s,variant:"contained",color:"primary",type:"submit",disabled:n||!S||l.hasFormErrors(),"data-testid":$e,children:"Save strategy"}),r(Oe,{type:"button",color:"primary",onClick:a||q,disabled:n,children:"Cancel"})]})]})},Te={name:"flexibleRollout",constraints:[],parameters:{rollout:"100",stickiness:"default",groupId:""}},Wt=()=>{var F;const e=Y("projectId"),s=N("environmentId"),{project:t,refetch:i}=le(e),a=(F=t.environments.find(T=>T.environment===s))==null?void 0:F.defaultStrategy,[n,o]=w.useState(a||Te),[d,f]=w.useState([]),{updateDefaultStrategy:h,loading:l}=ue(),{strategyDefinition:S}=X(n==null?void 0:n.name),{setToastData:c,setToastApiError:u}=z(),m=de(),{uiConfig:g}=ee(),{unleashUrl:v}=g,x=J(),{trackEvent:D}=ge(),{segments:A,refetchSegments:y}=he();w.useEffect(()=>{if(A&&(a!=null&&a.segments)){const T=[];for(const P of a==null?void 0:a.segments)T.push(...A.filter(V=>V.id===P));f(T)}},[JSON.stringify(A),JSON.stringify(a==null?void 0:a.segments)]);const q=g!=null&&g.flags.SE?d:[],k=Tt(n,q),p=async T=>{await h(e,s,T),D("default_strategy",{props:{action:"edit",hasTitle:!!T.title}}),await y(),c({title:"Default Strategy updated",type:"success",confetti:!0})},E=async()=>{const T=`/projects/${e}/settings/default-strategy`;try{await p(k),await i(),x(T)}catch(P){u(B(P))}};return!S||!n?null:r(fe,{modal:!0,title:pe((n==null?void 0:n.name)??""),description:Et,documentationLink:wt,documentationLinkLabel:At,formatApiCode:()=>Ct(e,s,k,S,v),children:r(vt,{projectId:e,strategy:n,setStrategy:o,segments:d,setSegments:f,environmentId:s,onSubmit:E,loading:l,permission:qe,errors:m,isChangeRequest:!1})})},Tt=(e,s)=>({name:e.name,title:e.title,constraints:e.constraints??[],parameters:e.parameters??{},segments:s.map(t=>t.id),disabled:e.disabled??!1}),Ct=(e,s,t,i,a)=>{if(!a)return"";const n={...t,parameters:_e(t.parameters??{},i)},o=`${a}/api/admin/projects/${e}/environments/${s}/default-strategy}`,d=JSON.stringify(n,void 0,2);return`curl --location --request PUT '${o}' \\
|
|
2
2
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
3
|
--header 'Content-Type: application/json' \\
|
|
4
4
|
--data-raw '${d}'`},Et=`
|
package/frontend/build/static/{FeatureMetricsChart-e1a34382.js → FeatureMetricsChart-70a6747e.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f_ as c,b as m,bK as g,r as d,j as u}from"./index-
|
|
1
|
+
import{f_ as c,b as m,bK as g,r as d,j as u}from"./index-78d048a4.js";import{d as b,L as x,C as f,a as C,b as v,P as S,c as h,T as q,p as k,e as M,f as L}from"./chartjs-adapter-date-fns.esm-04fda623.js";import"./index-b74e9af8.js";import"./index-545ad556.js";const $=(e,s,n)=>{const a={label:"Total requests",borderColor:e.palette.primary.main,backgroundColor:e.palette.primary.main,data:p(s,n,o=>o.yes+o.no),elements:{point:{radius:6,pointStyle:"circle"},line:{borderDash:[8,4]}}},t={label:"Exposed",borderColor:e.palette.success.main,backgroundColor:e.palette.success.main,data:p(s,n,o=>o.yes),elements:{point:{radius:6,pointStyle:"triangle"}}},r={label:"Not exposed",borderColor:e.palette.error.main,backgroundColor:e.palette.error.main,data:p(s,n,o=>o.no),elements:{point:{radius:6,pointStyle:"triangle",pointRotation:180}}};return{datasets:[t,r,a]}},p=(e,s,n)=>e.map(a=>({x:a.timestamp,y:n(a),variants:a.variants})),E=(e,s)=>{if(s===0)return"";const[n,a]=e,t=Math.floor(Number(a)/s*100);return`${a} (${t}%) - ${n}`},P=(e,s,n,a)=>({locale:a.locale,responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},color:e.palette.text.secondary,plugins:{tooltip:{backgroundColor:e.palette.background.paper,bodyColor:e.palette.text.primary,titleColor:e.palette.text.secondary,borderColor:e.palette.primary.main,borderWidth:1,padding:10,boxPadding:5,usePointStyle:!0,itemSort:(t,r)=>{const o=["Total requests","Exposed","Not exposed"],l=o.indexOf(t.dataset.label),i=o.indexOf(r.dataset.label);return l-i},callbacks:{label:t=>`${t.formattedValue} - ${t.dataset.label}`,afterLabel:t=>{const r=t.dataset.data[t.dataIndex];if(t.dataset.label!=="Exposed"||r.variants===void 0)return"";const{disabled:o,...l}=r.variants;return Object.entries(l).map(i=>E(i,r.y)).join(`
|
|
2
2
|
`)},title:t=>`Time: ${c(t[0].parsed.x,a.locale)}`}},legend:{position:"top",align:"end",labels:{boxWidth:10,boxHeight:10,usePointStyle:!0}},title:{text:T(n),position:"top",align:"start",display:!0,font:{size:16,weight:"400"},color:e.palette.text.primary}},scales:{y:{type:"linear",title:{display:!0,text:"Number of requests",color:e.palette.text.secondary},suggestedMin:0,ticks:{precision:0,color:e.palette.text.secondary},grid:{color:e.palette.divider,borderColor:e.palette.divider}},x:{type:"time",time:{unit:"hour"},grid:{display:!1},ticks:{callback:(t,r,o)=>c(o[r].value,a.locale),color:e.palette.text.secondary}}}}),T=e=>e===1?"Requests in the last hour":`Requests in the last ${e} hours`;b.font={...b.font,family:"Sen",size:13,weight:"400"};const R=({metrics:e,hoursBack:s,statsSectionId:n})=>{const a=m(),{locationSettings:t}=g(),r=d.useMemo(()=>[...e].sort((i,y)=>i.timestamp.localeCompare(y.timestamp)),[e]),o=d.useMemo(()=>P(a,r,s,t),[a,r,s,t]),l=d.useMemo(()=>$(a,r,t),[a,r,t]);return u("div",{style:{height:400},children:u(x,{options:o,data:l,"aria-label":"A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.","aria-describedby":n})})};f.register(C,v,S,h,q,k,M,L);export{R as FeatureMetricsChart,R as default};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{aB as En,aC as Rn,t as d,r as m,aD as In,aE as Dn,aF as bt,j as t,aG as kn,aH as Fn,E as Gt,aI as I,aJ as z,aK as Bn,h as c,aL as $n,C as T,aM as te,aN as he,aO as X,aP as be,aQ as Pn,aR as ct,aS as xe,aT as Ve,aU as lt,aV as On,aW as Vn,aX as Mn,aY as _n,m as K,aZ as Me,a_ as ye,n as U,T as j,a$ as Ae,b0 as Se,b1 as Ln,b2 as se,b3 as oe,b4 as J,I as Ee,b5 as Nn,b6 as zn,b7 as Re,ah as fe,b8 as $e,b9 as Yt,ba as Ce,bb as ie,as as ce,A as le,bc as Kt,bd as jn,be as Wn,bf as Un,bg as qn,bh as nt,bi as Hn,bj as Gn,F as O,B as Y,bk as Yn,bl as Kn,bm as Jn,bn as Xn,bo as Qn,bp as Zn,bq as ea,br as ta,bs as na,X as aa,b as Jt,d as _e,G as ve,bt as dt,ai as de,bu as oa,bv as ne,a0 as ut,bw as Pe,z as Le,a4 as sa,bx as pt,by as ge,bz as ra,x as Xt,a6 as Ne,bA as ia,bB as ae,bC as ca,bD as la,a3 as da,bE as ua,bF as pa,bG as ga,bH as Qt,bI as ha,bJ as fa,bK as Zt,bL as ma,bM as en,bN as ya,bO as Sa,y as gt,bP as ba,bQ as Ca,bR as ze,bS as va,$ as tn,ao as we,bT as wa,bU as Ta,bV as at,bW as nn,bX as an,bY as re,bZ as ot,b_ as xa,al as on,b$ as sn,ad as ht,am as Aa,c0 as rn,c1 as Ea,c2 as cn,c3 as Ra,c4 as Ia,c5 as ln,c6 as Da,c7 as ka,q as Fa,av as Ba,c8 as pe,c9 as Ct,ca as $a,cb as Pa,cc as Oa,P as ft,o as Va,S as vt,cd as Ma,ce as _a,cf as La,cg as wt,U as dn,ch as Na,f as Ue,g as za,K as ja,M as Wa,N as Ua,O as qa,Q as Ha,R as Ga,ci as Ya,cj as Tt,ck as Ka,cl as un,cm as Ja,an as Xa,cn as xt,co as Qa,cp as Za,cq as eo,cr as to,cs as no,ct as ao,a as oo,cu as so,cv as ro,cw as io,cx as co,cy as lo,cz as uo}from"./index-7bc6399c.js";import{C as mt,f as pn,E as po,F as go,V as ho,a as fo,u as mo,b as yo,T as So,c as bo,d as Co,W as vo,e as wo,g as To}from"./FeatureArchiveDialog-4d2f3953.js";import{S as xo}from"./StrategyItemContainer-0c77dc4b.js";import{u as Ao}from"./stringify-ec884b6d.js";function Eo(e){return En("MuiCardContent",e)}Rn("MuiCardContent",["root"]);const Ro=["className","component"],Io=e=>{const{classes:n}=e;return Fn({root:["root"]},Eo,n)},Do=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),ko=m.forwardRef(function(n,a){const o=In({props:n,name:"MuiCardContent"}),{className:s,component:l="div"}=o,r=Dn(o,Ro),i=bt({},o,{component:l}),p=Io(i);return t(Do,bt({as:l,className:kn(p.root,s),ownerState:i,ref:a},r))}),Fo=ko,Bo=Gt(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),$o=Gt(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"),Po=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Oo=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n);return a.name?t(Po,{children:t(Bn,{title:"Event log",feature:n,displayInline:!0})}):null},Vo=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"}})),Mo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),_o=d("div")({display:"flex",alignItems:"center"}),Lo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),No=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),At=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Et=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),zo=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n),{project:o,description:s,type:l}=a,r=Pn(l);return t(Vo,{children:c(Mo,{children:[c(_o,{"data-loading":!0,children:[t(r,{sx:i=>({marginRight:i.spacing(2),height:"40px",width:"40px",fill:i.palette.primary.contrastText})})," ",c(Lo,{children:[$n(l||"")," toggle"]})]}),c(No,{children:[c(At,{"data-loading":!0,children:["Project: ",o]}),t(T,{condition:!!s,show:c(At,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(Et,{children:[t("p",{children:s}),t(te,{projectId:e,permission:he,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(be,{sx:i=>({color:i.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:c(Et,{children:["No description."," ",t(te,{projectId:e,permission:he,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(be,{sx:i=>({color:i.palette.primary.contrastText})})})]})})})]})]})})},Rt={lastHourUsage:[],seenApplications:[]},jo=(e,n,a={})=>{const o=async()=>{const g=xe(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Ve("feature metrics"));return h.ok?h.json():Rt},s=`${e}_${n}_metrics`,{data:l,error:r}=ct(s,o,{...a}),[i,p]=m.useState(!r&&!l),u=()=>{lt(s)};return m.useEffect(()=>{p(!r&&!l)},[l,r]),{metrics:l||Rt,error:r,loading:i,refetch:u,FEATURE_METRICS_CACHE_KEY:s}},Wo=e=>({yes:0,no:0,environment:e,timestamp:""}),Uo=(e,n)=>e.map(a=>n.lastHourUsage.find(s=>s.environment===a.name)||Wo(a.name)),qo=e=>(n,a,o)=>(o.revalidateOnFocus=!1,o.revalidateIfStale=!1,o.revalidateOnReconnect=!1,e(n,a,o)),Ho=On(ct,qo),gn=(e,n)=>{const{refetchFeature:a}=z(e,n),o=Vn(e,n),{data:s,error:l,mutate:r}=Ho(["useFeatureImmutable",o],()=>Mn(o)),i=m.useCallback(async()=>{await r(),await a()},[r,a]);return{feature:(s==null?void 0:s.body)||_n,refetchFeature:i,loading:!l&&!s,status:s==null?void 0:s.status,error:l}},yt=(e,n,a)=>{const{setToastData:o,setToastApiError:s}=K(),{addChange:l}=Me(),{refetch:r}=ye(e),[i,p]=m.useState({isOpen:!1}),u=m.useCallback((w,x,b)=>{p({featureName:n,environment:w,fromEnvironment:b,strategy:x,isOpen:!0})},[]),g=m.useCallback((w,x,b)=>{p({featureName:n,environment:w,fromEnvironment:b,strategies:x,isOpen:!0})},[]),h=m.useCallback(()=>{p({isOpen:!1})},[]),f=m.useCallback(async()=>{try{await l(e,i.environment,{feature:i.featureName,action:a,payload:i.strategy}),r(),p({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(w){s(U(w)),p({isOpen:!1})}},[l]),S=m.useCallback(async()=>{try{await Promise.all(i.strategies.map(w=>l(e,i.environment,{feature:i.featureName,action:a,payload:w}))),r(),p({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(w){s(U(w)),p({isOpen:!1})}},[l]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:f,onChangeRequestAddStrategiesConfirm:S,changeRequestDialogDetails:i}},Go=({payload:e,fromEnvironment:n,environment:a})=>c(j,{children:[c("strong",{children:["Copy ",Ae((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Yo=({environmentId:e,environments:n,strategy:a})=>{const o=I("projectId"),s=I("featureId"),[l,r]=m.useState(null),i=!!l,{addStrategyToFeature:p}=Se(),{setToastData:u,setToastApiError:g}=K(),{refetchFeature:h}=z(o,s),{refetchFeature:f}=gn(o,s),S=()=>{r(null)},w=Ln(o),{isChangeRequestConfigured:x}=se(o),{changeRequestDialogDetails:b,onChangeRequestAddStrategyClose:C,onChangeRequestAddStrategy:D,onChangeRequestAddStrategyConfirm:k}=yt(o,s,"addStrategy"),$=async F=>{const{id:V,...B}={...a,targetEnvironment:F};if(x(F)){await D(F,{id:V,...B},e);return}try{await p(o,s,F,a),h(),f(),u({title:"Strategy created",text:`Successfully copied a strategy to ${F}`,type:"success"})}catch(q){g(U(q))}S()},P=n.some(F=>w(oe,F));return c("div",{children:[t(mt,{isOpen:b.isOpen,onClose:C,environment:b==null?void 0:b.environment,onConfirm:k,messageComponent:t(Go,{fromEnvironment:b.fromEnvironment,payload:b.strategy})}),t(J,{title:`Copy to another environment${P?"":" (Access denied)"}`,children:t("div",{children:t(Ee,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:F=>{r(F.currentTarget)},"data-testid":Nn,disabled:!P,children:t(zn,{})})})}),t(Re,{id:"basic-menu",anchorEl:l,open:i,onClose:S,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(F=>{const V=w(oe,F);return t(J,{title:V?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(fe,{onClick:()=>$(F),disabled:!V,children:[t(T,{condition:!V,show:t($e,{children:t(Yt,{fontSize:"small"})})}),c(Ce,{children:["Copy to ",F]})]})})},F)})})]})},hn=()=>t(le,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Ko=({onRemove:e,onClose:n,isOpen:a})=>t(ie,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(hn,{})}),Jo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Xo=({onRemove:e,onClose:n,isOpen:a})=>c(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(hn,{}),t(Jo,{children:t(j,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(j,{fontWeight:"bold",children:"Remove strategy"})]}),Qo=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{deleteStrategyFromFeature:s}=Se(),{setToastData:l,setToastApiError:r}=K(),i=ce(),{refetchFeature:p}=z(e,n);return async g=>{try{g.preventDefault(),await s(e,n,a,o),l({title:"Strategy deleted",type:"success"}),p(),i(Kt(e,n))}catch(h){r(U(h))}}},Zo=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{addChange:s}=Me(),{refetch:l}=ye(e),{setToastData:r,setToastApiError:i}=K();return async u=>{try{u.preventDefault(),await s(e,a,{action:"deleteStrategy",feature:n,payload:{id:o}}),r({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(U(g))}}},es=({projectId:e,featureId:n,environmentId:a,strategyId:o,text:s,isOpen:l,onClose:r})=>{const{isChangeRequestConfigured:i}=se(e),p=Qo({featureId:n,projectId:e,strategyId:o,environmentId:a}),u=Zo({featureId:n,projectId:e,strategyId:o,environmentId:a});return i(a)?t(Xo,{isOpen:l,onClose:()=>r(),onRemove:async g=>{await u(g),r()}}):t(Ko,{isOpen:l,onClose:()=>r(),onRemove:p})},ts=({projectId:e,environmentId:n,featureId:a,strategy:o})=>{const{refetchFeature:s}=z(e,a),{setStrategyDisabledState:l}=Se(),{setToastData:r,setToastApiError:i}=K(),p=u=>async()=>{try{await l(e,a,n,o.id,!u),r({title:`Strategy ${u?"enabled":"disabled"}`,type:"success"}),s()}catch(g){i(U(g))}};return{onDisable:p(!1),onEnable:p(!0)}},ns=({projectId:e,environmentId:n,featureId:a,strategy:o})=>{const{addChange:s}=Me(),{refetch:l}=ye(e),{setToastData:r,setToastApiError:i}=K(),p=u=>async()=>{try{await s(e,n,{action:"updateStrategy",feature:a,payload:{...o,disabled:!u}}),r({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(U(g))}};return{onSuggestDisable:p(!1),onSuggestEnable:p(!0)}},as=({isOpen:e,onClose:n,...a})=>{var S;const{projectId:o,environmentId:s}=a,{isChangeRequestConfigured:l}=se(o),r=l(s),{onSuggestEnable:i,onSuggestDisable:p}=ns({...a}),{onEnable:u,onDisable:g}=ts({...a}),h=!!((S=a.strategy)!=null&&S.disabled);return t(ie,{title:r?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:r?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:w=>{w.preventDefault(),r?h?i():p():h?u():g(),n()},onClose:()=>n(),children:t(T,{condition:r,show:t(jn,{environment:s}),elseShow:c(le,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var St={},os=Un;Object.defineProperty(St,"__esModule",{value:!0});var fn=St.default=void 0,ss=os(Wn()),rs=qn,is=(0,ss.default)((0,rs.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"}),"Delete");fn=St.default=is;const cs=({projectId:e,strategy:n,featureId:a,environmentId:o})=>{const[s,l]=m.useState(null),[r,i]=m.useState(!1),[p,u]=m.useState(!1),g=!!s,h=x=>{l(x.currentTarget)},f=x=>{l(null),x.stopPropagation()},S=nt(Hn,e,o),w=nt(Gn,e,o);return c(O,{children:[t(Y,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(J,{title:"More actions",children:t(Ee,{onClick:h,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":Yn,children:t(Kn,{sx:{width:32,height:32}})})})}),c(Re,{anchorEl:s,id:"actions-menu",open:g,onClose:f,onClick:f,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Jn,children:[t(J,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:c(fe,{disabled:!S,onClick:()=>i(!0),children:[t($e,{children:n.disabled?t(Xn,{}):t(Qn,{})}),t(Ce,{children:n.disabled?"Enable":"Disable"})]})}),t(J,{title:"Remove strategy",arrow:!0,placement:"left",children:c(fe,{disabled:!w,onClick:()=>u(!0),"data-testid":Zn,children:[t($e,{children:t(fn,{})}),t(Ce,{children:"Remove"})]})})]}),t(as,{isOpen:r,onClose:()=>i(!1),projectId:e,featureId:a,environmentId:o,strategy:n}),t(es,{isOpen:p,onClose:()=>u(!1),projectId:e,featureId:a,environmentId:o,strategyId:n.id})]})},ls=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:o,otherEnvironments:s,orderNumber:l,headerChildren:r})=>{const i=I("projectId"),p=I("featureId"),u=ea(i,p,e,n.id);return t(xo,{strategy:n,onDragStart:a,onDragEnd:o,orderNumber:l,actions:c(O,{children:[r,t(T,{condition:!!(s&&(s==null?void 0:s.length)>0),show:()=>t(Yo,{environmentId:e,environments:s,strategy:n})}),t(te,{permission:ta,environmentId:e,projectId:i,component:X,to:u,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(be,{})}),t(cs,{projectId:i,featureId:p,environmentId:e,strategy:n})]}),children:t(na,{strategy:n})})},ds=(e,n,a,o)=>{const{data:s}=ye(e),l=s==null?void 0:s.find(p=>p.environment===a),r=l==null?void 0:l.features.find(p=>p.name===n);return r==null?void 0:r.changes.find(p=>p.action==="updateStrategy"||p.action==="deleteStrategy"?p.payload.id===o:!1)},us=({strategy:e,index:n,environmentName:a,otherEnvironments:o,isDragging:s,onDragStartRef:l,onDragOver:r,onDragEnd:i})=>{const p=I("projectId"),u=I("featureId"),g=m.useRef(null),h=ds(p,u,a,e.id);return c(Y,{ref:g,onDragOver:r(g,n),sx:{opacity:s?"0.5":"1"},children:[t(T,{condition:n>0,show:t(aa,{text:"OR"})}),t(ls,{strategy:e,environmentId:a,otherEnvironments:o,onDragStart:l(g,n),onDragEnd:i,orderNumber:n+1,headerChildren:t(ps,{change:h})})]},e.id)},ps=({change:e})=>{const n=Jt();return _e(n.breakpoints.down("sm"))?null:c(Y,{sx:{mr:1.5},children:[t(T,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(ve,{color:"warning",children:"Modified in draft"})}),t(T,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(ve,{color:"error",children:"Deleted in draft"})})]})},gs=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}})),hs=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})),mn=({children:e})=>t(gs,{children:t(hs,{children:e})}),fs=({environmentId:e,environments:n,onClick:a})=>{const o=I("projectId"),[s,l]=m.useState(null),r=!!s,{hasAccess:i}=m.useContext(dt),p=n.some(u=>i(oe,o,u));return c("div",{children:[t(J,{title:p?"":"(Access denied)",children:t("div",{children:t(de,{id:`copy-all-strategies-${e}`,"aria-controls":r?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":r?"true":void 0,onClick:u=>{l(u.currentTarget)},disabled:!p,variant:"outlined",children:"Copy from another environment"})})}),t(Re,{id:"basic-menu",anchorEl:s,open:r,onClose:()=>{l(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=i(oe,o,u);return t(J,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(fe,{onClick:()=>a(u),disabled:!g,children:[t(T,{condition:!g,show:t($e,{children:t(Yt,{fontSize:"small"})})}),c(Ce,{children:["Copy from ",u]})]})})},u)})})]})},ms=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),ys=({payload:e,fromEnvironment:n,environment:a})=>c(ms,{children:[t(j,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(o=>c(j,{children:[c("strong",{children:[Ae((o==null?void 0:o.name)||"")," strategy"," "]})," "]})),c(j,{children:["from ",n," to ",a]})]}),Ss=({payload:e,environment:n})=>c(O,{children:[t(j,{component:"span",children:"Add "}),c("strong",{children:[Ae((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),bs=d(oa)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),It=({title:e,children:n,featureId:a,projectId:o,environmentId:s,strategy:l,Icon:r,onAfterAddStrategy:i})=>{const{addStrategyToFeature:p}=Se(),{setToastApiError:u}=K(),{isChangeRequestConfigured:g}=se(o),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:f,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategyClose:w}=yt(o,a,"addStrategy");return c(O,{children:[t(bs,{variant:"outlined",children:c(Fo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(j,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(j,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(Y,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(ne,{permission:oe,projectId:o,environmentId:s,variant:"outlined",size:"small",onClick:async()=>{try{g(s)?f(s,l):(await p(o,a,s,l),i())}catch(b){u(U(b))}},children:"Use template"})})]})}),t(mt,{isOpen:h.isOpen,onClose:w,environment:h==null?void 0:h.environment,onConfirm:S,messageComponent:t(Ss,{environment:s,payload:h.strategy})})]})},Cs=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}})),vs=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ws=d(ut)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Ts=d(X)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),qe=({projectId:e,featureId:n,environmentId:a,strategy:o,defaultStrategy:s})=>{const l=Pe(o.name),r=Ae(o.name),{trackEvent:i}=Le(),p=pn(e,n,a,o.name,s);return c(Ts,{to:p,onClick:()=>{i("strategy-add",{props:{buttonTitle:o.displayName||r}})},children:[t(Cs,{children:t(l,{})}),c("div",{children:[t(ws,{text:o.displayName||r,maxWidth:"200",maxLength:25}),t(vs,{children:o.description})]})]})},He=d(j)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),yn=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:o}=sa(),s=o.filter(i=>!i.deprecated&&!i.editable),l=o.filter(i=>!i.deprecated&&i.editable),r={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return c(pt,{dense:!0,children:[c(O,{children:[c(He,{color:"textSecondary",children:[a," environment default strategy"]}),t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:r,defaultStrategy:!0})},r.name)]}),t(He,{color:"textSecondary",children:"Predefined strategy types"}),s.map(i=>t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name)),t(T,{condition:l.length>0,show:c(O,{children:[t(He,{color:"textSecondary",children:"Custom strategies"}),l.map(i=>t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name))]})})]})},xs=d(ne)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),st=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,size:l,matchWidth:r})=>{const[i,p]=m.useState(),u=ce(),{trackEvent:g}=Le(),h=!!i,f=h?"FeatureStrategyMenuPopover":void 0,S=()=>{p(void 0)},w=C=>{g("strategy-add",{props:{buttonTitle:e}}),u(b)},x=C=>{p(C.currentTarget)},b=pn(n,a,o,"flexibleRollout",!0);return c("div",{onClick:C=>C.stopPropagation(),children:[t(ne,{permission:oe,projectId:n,environmentId:o,onClick:w,"aria-labelledby":f,variant:s,size:l,sx:{minWidth:r?"282px":"auto"},children:e}),t(xs,{permission:oe,projectId:n,environmentId:o,onClick:x,"aria-labelledby":f,variant:"outlined",size:l,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(ra,{sx:C=>({margin:C.spacing(.25,0)})})}),t(Xt,{id:f,open:h,anchorEl:i,onClose:S,onClick:S,PaperProps:{sx:C=>({paddingBottom:C.spacing(1)})},children:t(yn,{projectId:n,featureId:a,environmentId:o})})]})},rt=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,matchWidth:l})=>{const[r,i]=m.useState(),p=!!r,u=p?"FeatureStrategyMenuPopover":void 0,g=()=>{i(void 0)};return c("div",{onClick:f=>f.stopPropagation(),children:[t(ne,{permission:oe,projectId:n,environmentId:o,onClick:f=>{i(f.currentTarget)},"aria-labelledby":u,variant:s,sx:{minWidth:l?"282px":"auto"},children:e}),t(Xt,{id:u,open:p,anchorEl:r,onClose:g,onClick:g,children:t(yn,{projectId:n,featureId:a,environmentId:o})})]})},As=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Es=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Rs=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),Is=({projectId:e,featureId:n,environmentId:a})=>{var $;const{addStrategyToFeature:o}=Se(),{setToastData:s,setToastApiError:l}=K(),{refetchFeature:r}=z(e,n),{refetchFeature:i}=gn(e,n),{feature:p}=z(e,n),u=p==null?void 0:p.environments.filter(P=>P.name!==a&&P.strategies&&P.strategies.length>0),{isChangeRequestConfigured:g}=se(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:f,onChangeRequestAddStrategiesConfirm:S,onChangeRequestAddStrategyClose:w}=yt(e,n,"addStrategy"),{uiConfig:x}=Ne(),b=($=x==null?void 0:x.flags)==null?void 0:$.strategySplittedButton,C=(P=!1)=>{r(),i(),s({title:P?"Strategies created":"Strategy created",text:P?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},D=async P=>{var V;const F=((V=u==null?void 0:u.find(B=>B.name===P))==null?void 0:V.strategies)||[];if(g(a)){await f(a,F,P);return}try{await Promise.all(F.map(B=>{const{id:q,...H}={...B,environment:a};return o(e,n,a,H)})),C(!0)}catch(B){l(U(B))}},k=u&&u.length>0;return c(O,{children:[t(mt,{isOpen:h.isOpen,onClose:w,environment:h==null?void 0:h.environment,onConfirm:S,messageComponent:t(ys,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(As,{children:[t(Es,{children:"You have not defined any strategies yet."}),c(Rs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Y,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(T,{condition:!!b,show:t(st,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:k}),elseShow:t(rt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:k})}),t(T,{condition:k,show:t(fs,{environmentId:a,environments:u.map(P=>P.name),onClick:D})})]}),t(T,{condition:b===!1,show:c(O,{children:[t(Y,{sx:{width:"100%",mt:3},children:t(mn,{children:"Or use a strategy template"})}),c(Y,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(It,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:C,Icon:Pe("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(It,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:C,Icon:Pe("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:p.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})})]})]})},Ds=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ks=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Fs=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const o=I("projectId"),s=I("featureId"),{setStrategiesSortOrder:l}=Se(),{setToastData:r,setToastApiError:i}=K(),{refetchFeature:p}=z(o,s),[u,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,f]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const S=async C=>{try{await l(o,s,e.name,C),p(),r({title:"Order of strategies updated",type:"success"})}catch(D){i(U(D))}},w=(C,D)=>k=>{var $;f({id:u[D].id,index:D,height:(($=C.current)==null?void 0:$.offsetHeight)||0}),C!=null&&C.current&&(k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/html",C.current.outerHTML),k.dataTransfer.setDragImage(C.current,20,20))},x=C=>(D,k)=>$=>{if(h===null||D.current===null||h.index===k||C===h.id)return;const{top:P,bottom:F}=D.current.getBoundingClientRect(),V=$.clientY-P<h.height,B=F-$.clientY<h.height,q=h.index>k;if(V&&q||B&&!q){const H=[...u],Z=H.splice(h.index,1)[0];H.splice(k,0,Z),g(H),f({...h,index:k})}},b=()=>{f(null),S(u.map((C,D)=>({id:C.id,sortOrder:D})))};return t(Ds,{children:c(ks,{children:[t(T,{condition:u.length>0&&n,show:()=>t(le,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(T,{condition:u.length>0,show:t(O,{children:u.map((C,D)=>t(us,{strategy:C,index:D,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===C.id,onDragStartRef:w,onDragOver:x(C.id),onDragEnd:b},C.id))}),elseShow:t(Is,{projectId:o,featureId:s,environmentId:e.name})})]})})},Sn=(e,n)=>e===0?0:Math.round(n/e*100);var je={},We={};Object.defineProperty(We,"__esModule",{value:!0});We.defaultOptions=void 0;We.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var me={};Object.defineProperty(me,"__esModule",{value:!0});me.roundTo=me.parseValue=void 0;function Bs(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}me.parseValue=Bs;function $s(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))}me.roundTo=$s;Object.defineProperty(je,"__esModule",{value:!0});je.millify=void 0;const Ge=We,Dt=me,kt=1e3;function*Ft(e){let n=kt;for(;;){const a=e/n;if(a<1)return;yield a,n*=kt}}function bn(e,n){var a;const o=n?Object.assign(Object.assign({},Ge.defaultOptions),n):Ge.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let s;try{s=Dt.parseValue(e)}catch(S){return S instanceof Error&&console.warn(`WARN: ${S.message} (millify)`),String(e)}const l=s<0?"-":"";s=Math.abs(s);let r=0;for(const S of Ft(s))s=S,r+=1;if(r>=o.units.length)return e.toString();let p=Dt.roundTo(s,o.precision);for(const S of Ft(p))p=S,r+=1;const u=(a=o.units[r])!==null&&a!==void 0?a:"",g=o.lowercase?u.toLowerCase():u,h=o.space?" ":"",f=p.toString().replace(Ge.defaultOptions.decimalSeparator,o.decimalSeparator);return`${l}${f}${h}${g}`}je.millify=bn;var Ps=je.default=bn;const Oe=({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 l=t("span",{"data-testid":ia,children:o});return t(T,{condition:s,show:t(J,{title:e.toLocaleString(),arrow:!0,children:l}),elseShow:l})},Ye=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Ke=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),Je=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),Xe=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 l=a===1?"in the last hour":`in the last ${a} hours`;return c(ae,{container:!0,spacing:2,id:o,"aria-describedby":s,"aria-label":"Feature metrics summary",component:"section",children:[t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Exposure"}),t(Je,{children:t(Oe,{value:e})}),c(Xe,{children:["Total exposure of the feature in the environment"," ",l,"."]})]})}),t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Exposure %"}),c(Je,{children:[Sn(e+n,e),"%"]}),c(Xe,{children:["% total exposure of the feature in the environment"," ",l,"."]})]})}),t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Requests"}),t(Je,{children:t(Oe,{value:e+n})}),c(Xe,{children:["Total requests for the feature in the environment"," ",l,"."]})]})})]})},Os=({environmentMetric:e})=>e?c(O,{children:[t(mn,{children:"Feature toggle exposure"}),t("div",{children:t(Cn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Bt=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),$t=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Pt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Ot=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Vs=d(ca)(({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"}})),_s=({environmentMetric:e,disabled:n=!1})=>{const a=la();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(Bt,{children:[c($t,{children:[c(Pt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[s,"%"]}),c(Ot,{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(Vs,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Bt,{children:[c($t,{children:[c(Pt,{children:[s,"%"]}),c(Ot,{children:["The feature has been requested"," ",c("b",{children:[t(Oe,{value:o})," times"]})," ","and exposed"," ",c("b",{children:[t(Oe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(Ms,{"data-loading":!0,children:t(da,{percentage:s,size:"3rem"})})]})},Ls=({strategyName:e})=>{const n=Pe(e);return t(J,{title:Ae(e),arrow:!0,children:t(Ns,{children:t(n,{})})})},Ns=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)}})),zs=({strategies:e})=>e!=null&&e.length?t(js,{"aria-label":"Feature strategies",children:e.map(n=>t(Ws,{children:t(Ls,{strategyName:n.name})},n.id))}):null,js=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Ws=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Us=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})),qs=d(ua)({boxShadow:"none",background:"none"}),Hs=d(pa)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Gs=d(ga,{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)}})),Ys=d(Fs)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ks=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})),Js=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Xs=d(po)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Qs=d(ut)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Zs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),er=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),[e.breakpoints.down(560)]:{flexDirection:"column"}})),tr=({env:e})=>{var h,f;const n=I("projectId"),a=I("featureId"),{metrics:o}=jo(n,a),{feature:s}=z(n,a),{value:l}=Qt(),{uiConfig:r}=Ne(),i=(h=r==null?void 0:r.flags)==null?void 0:h.strategySplittedButton,u=Uo(s==null?void 0:s.environments,o).find(S=>S.environment===e.name),g=s==null?void 0:s.environments.find(S=>S.name===e.name);return t(T,{condition:!new Set(l.hiddenEnvironments).has(e.name),show:t(Us,{enabled:e.enabled,children:c(qs,{"data-testid":`${ha}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(Hs,{expandIcon:t(fa,{titleAccess:"Toggle"}),children:[c(Ks,{"data-loading":!0,enabled:e.enabled,children:[c(Js,{children:[t(Xs,{enabled:e.enabled}),t("div",{children:t(Qs,{text:e.name,maxWidth:"100",maxLength:15})}),t(T,{condition:!e.enabled,show:t(ve,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),t(T,{condition:!!i,show:t(er,{children:t(st,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"})}),elseShow:c(Zs,{children:[t(rt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(zs,{strategies:g==null?void 0:g.strategies})]})})]}),t(_s,{environmentMetric:u,disabled:!e.enabled})]}),c(Gs,{enabled:e.enabled,children:[t(Ys,{featureEnvironment:g,isDisabled:!e.enabled,otherEnvironments:s==null?void 0:s.environments.map(({name:S})=>S).filter(S=>S!==e.name)}),t(T,{condition:(((f=g==null?void 0:g.strategies)==null?void 0:f.length)||0)>0,show:c(O,{children:[t(Y,{sx:{display:"flex",justifyContent:"center",py:1},children:t(T,{condition:!!i,show:t(st,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name}),elseShow:t(rt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})})}),t(Os,{environmentMetric:u})]})})]})]})})})},nr=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n);if(!a)return null;const{environments:o}=a;return t(O,{children:o==null?void 0:o.map(s=>t(tr,{env:s},s.name))})},ar=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),or=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),sr=({feature:e,header:n})=>{const{locationSettings:a}=Zt();return c(ar,{children:[n,c("div",{"data-loading":!0,children:[t(or,{children:"Created at:"}),t("span",{children:ma(en(e.createdAt),a.locale)})]})]})},rr=d(Ee,{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}})),ir=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(rr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(T,{condition:n.has(e.name),show:t(ya,{}),elseShow:t(Sa,{})})}),cr=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),lr=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),dr=({environment:e,callback:n,showInfoBox:a,children:o,hiddenEnvironments:s,setHiddenEnvironments:l})=>{const{name:r,enabled:i}=e,p=I("projectId"),u=I("featureId"),{feature:g,refetchFeature:h}=z(p,u),f=c(O,{children:[" ",c("span",{"data-loading":!0,children:[i?"enabled":"disabled"," in"]})," ",t(ut,{text:r,maxWidth:"120",maxLength:15})]}),S=()=>{h(),n&&n()};return c(cr,{children:[c(lr,{children:[t(go,{featureId:g.name,projectId:p,environmentName:e.name,onToggle:S,onError:a,value:i}),o??f]}),t(ir,{environment:e,hiddenEnvironments:s,setHiddenEnvironments:l})]})},ur=d("div")(({theme:e})=>({padding:e.spacing(3)})),pr=d("div")(()=>({display:"flex",flexDirection:"column"})),gr=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),hr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Vt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),fr=d(gt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),mr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:o})=>{const[s,l]=m.useState(!1),[r,i]=m.useState(""),p=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return c(ur,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],f=h.length>0&&c(O,{children:[t(Vt,{}),t(J,{title:"View variants",arrow:!0,describeChild:!0,children:t(fr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),S=u.enabled&&h.length===0&&p;return t(dr,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:o,showInfoBox:()=>{i(u.name),l(!0)},children:c(pr,{children:[t(gr,{children:u.name}),c(hr,{children:[g,f,t(T,{condition:S,show:c(O,{children:[t(Vt,{}),t(ho,{})]})})]})]})},u.name)}),t(fo,{open:s,onClose:()=>l(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},vn=(e,n={})=>{const a=async()=>{const u=xe(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Ve("Tags"))).json()},o=`api/admin/features/${e}/tags`,{data:s,error:l}=ba(!!e,{tags:[]},o,a,n),[r,i]=m.useState(!l&&!s),p=()=>{lt(o)};return m.useEffect(()=>{i(!l&&!s)},[s,l]),{tags:(s==null?void 0:s.tags)||[],error:l,loading:r,refetch:p}},yr=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),Qe=e=>e.map(n=>({title:n.value})),Mt=(e,n)=>e.map(a=>({value:a.title,type:n})),wn=({open:e,setOpen:n})=>{const{tagTypes:a}=Ca(),o=I("featureId"),{createTag:s}=mo(),{updateFeatureTags:l,loading:r}=ze(),{tags:i,refetch:p,loading:u}=vn(o),{setToastData:g}=K(),h=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[f,S]=m.useState(h),w=r||u,[x,b]=m.useState(0),{trackEvent:C}=Le(),[D,k]=m.useState(Qe(i.filter(v=>v.type===f.name))),{tags:$,refetch:P}=yo(f.name),F=m.useMemo(()=>Qe($),[$]);m.useEffect(()=>{i&&f&&k(Qe(i.filter(v=>v.type===f.name)))},[JSON.stringify(i),f]);const V=()=>{n(!1),k([])};function B(v,E){const _=v.filter(L=>L.type===f.name).filter(L=>!E.find(W=>L.value===W.value&&L.type===W.type)),N=E.filter(L=>L.type===f.name).filter(L=>!v.find(W=>L.value===W.value&&L.type===W.type));return b(_.length+N.length),{added:_,removed:N}}const q=v=>v.filter(E=>!E.title.startsWith("Create")),H=async(v,E)=>{try{await l(o,{addedTags:v,removedTags:E}),await p()}catch(_){const N=U(_);g({type:"error",title:"Failed to add tag",text:N,confetti:!1})}},Z=(v,E)=>{let _="We successfully";return v>0&&(_=_.concat(` added ${v} new tag${v>1?"s":""}`)),v>0&&E>0&&(_=_.concat(" and ")),E>0&&(_=_.concat(` removed ${E} tag${E>1?"s":""}`)),_},ee=async v=>{v.preventDefault();const E=Mt(q(D),f.name),{added:_,removed:N}=B(E,i);x>0&&(await H(_,N),x>1&&C("suggest_tags",{props:{eventType:"multiple_tags_added"}}),x>0&&g({type:"success",title:`Updated tag${_.length>1?"s":""} to toggle`,text:Z(_.length,N.length),confetti:!0})),b(0),k([]),n(!1)},A=(v,E)=>{E!=null&&typeof E!="string"&&(v.preventDefault(),S(E),k([]),b(0))},M=(v,E,_)=>{const N=va(E);_==="selectOption"&&E.forEach((W,Ie)=>{if(typeof W!="string"&&W.inputValue&&W.inputValue!==""){const De={value:W.inputValue,type:f.name};s(De).then(()=>{C("suggest_tags",{props:{eventType:"tag_created"}}),P()}),W.title=W.inputValue,W.inputValue="",N[Ie]=W}});const L=Mt(q(N),f.name);B(L,i),k(N)},y="add-tag-form";return t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:ee,disabledPrimaryButton:w||x===0,onClose:V,formId:y,children:c(O,{children:[t(j,{paragraph:!0,sx:{marginBottom:v=>v.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:y,onSubmit:ee,children:c(yr,{children:[t(So,{options:a,value:f,onChange:A}),t(bo,{options:F,existingTags:i,tagType:f,selectedOptions:D,onChange:M})]})})]})})},Sr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),br=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Cr=d(tn)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),vr=d(we)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),wr=d(de)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Tr=({feature:e,header:n})=>{const{tags:a,refetch:o}=vn(e.name),{deleteTagFromFeature:s}=ze(),[l,r]=m.useState(!1),[i,p]=m.useState(!1),[u,g]=m.useState(),{setToastData:h,setToastApiError:f}=K(),{hasAccess:S}=m.useContext(dt),w=S(he,e.project),x=async()=>{if(u)try{await s(e.name,u.type,u.value),o(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(b){f(U(b))}};return c(Sr,{children:[n,t(br,{children:a.map(b=>{const C=`${b.type}:${b.value}`;return t(Cr,{label:C,deleteIcon:t(wa,{titleAccess:"Remove"}),onDelete:w?()=>{p(!0),g(b)}:void 0},C)})}),t(T,{condition:w,show:c(O,{children:[t(T,{condition:a.length>0,show:t(vr,{})}),t(wr,{"data-loading":!0,variant:"outlined",startIcon:t(Ta,{}),onClick:()=>r(!0),children:"Add new tag"})]})}),t(wn,{open:l,setOpen:r}),c(ie,{open:i,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{p(!1),g(void 0)},onClick:()=>{p(!1),x(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},xr=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"}})),Ze=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}})),Ar=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=I("projectId"),o=I("featureId"),{feature:s}=z(a,o);return c(xr,{children:[t(mr,{header:c(Ze,{"data-loading":!0,children:["Enabled in environments (",s.environments.filter(({enabled:l})=>l).length,")",t(at,{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(we,{}),t(sr,{header:t(Ze,{"data-loading":!0,children:"Feature toggle details"}),feature:s}),t(we,{}),t(Tr,{header:t(Ze,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:s})]})},Er=()=>{const{trackEvent:e}=Le(),{value:n,setValue:a}=Qt(),[o,s]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:o,setHiddenEnvironments:r=>{a(i=>{const p=new Set(i.hiddenEnvironments);return p.has(r)?(p.delete(r),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(p.add(r),e("hidden_environment",{props:{eventType:"environment hidden"}})),s(p),{...n,hiddenEnvironments:p}})}}},Rr=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Ir=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),Dr=()=>{const e=ce(),n=I("projectId"),a=I("featureId"),o=Kt(n,a),{hiddenEnvironments:s,setHiddenEnvironments:l}=Er(),r=()=>e(o);return nn(a),c(Rr,{children:[c("div",{children:[t(zo,{}),t(Ar,{hiddenEnvironments:s,setHiddenEnvironments:l})]}),t(Ir,{children:t(nr,{})}),c(an,{children:[t(re,{path:"strategies/create",element:t(ot,{label:"Create feature strategy",onClose:r,open:!0,children:t(Co,{})})}),t(re,{path:"strategies/edit",element:t(ot,{label:"Edit feature strategy",onClose:r,open:!0,children:t(xa,{})})})]})]})},kr=({values:e=[],updateValues:n,placeholder:a="",error:o,...s})=>{const l=i=>{const u=i.target.value.split(/,\s?/).map(g=>g.trim());n(u)},r=i=>{if(i.key==="Backspace"){const p=i.target.value;if(p.endsWith(", ")){i.preventDefault();const u=p.slice(0,-2);n(u.split(/,\s*/))}}};return t(on,{...s,error:o,placeholder:a,value:e?e.join(", "):"",onKeyDown:r,onChange:l,style:{width:"100%"},variant:"outlined",size:"small"})},Fr=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"}}})),Br=d(sn)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),$r=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),Pr=d(kr)(()=>({width:"100%"})),Or=d(on)(()=>({width:"100%"})),Vr=({overrides:e,overridesDispatch:n})=>{const{context:a}=ht(),o=a.map(({name:r})=>({key:r,label:r})),s=r=>i=>{n({type:"UPDATE_VALUES_AT",payload:[r,i]})},l=r=>(i,p)=>{i==null||i.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[r,p||[]]})};return t(O,{children:e.map((r,i)=>{var h;const p=a.find(({name:f})=>f===r.contextName),u=((h=p==null?void 0:p.legalValues)==null?void 0:h.map(({value:f})=>f))||[],g=r.values.filter(f=>u.includes(f));return c(Fr,{children:[t(Br,{id:"override-context-name",name:"contextName",label:"Context Field","data-testid":"context_field",value:r.contextName,options:o,onChange:f=>n({type:"UPDATE_TYPE_AT",payload:[i,f.target.value]})}),c($r,{children:[t(T,{condition:!!(u&&u.length>0),show:t(Aa,{multiple:!0,id:`override-select-${i}`,isOptionEqualToValue:(f,S)=>f===S,options:u,onChange:l(i),getOptionLabel:f=>f,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:f=>t(Or,{...f,variant:"outlined",label:"Legal values"})}),elseShow:t(Pr,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:r.values,updateValues:s(i),"data-testid":"OVERRIDE_VALUES"})}),t(J,{title:"Remove",arrow:!0,children:t(Ee,{onClick:f=>{f.preventDefault(),n({type:"REMOVE",payload:i})},children:t(rn,{})})})]})]},`override=${i}`)})})},Mr=(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,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,o]=n.payload;return e.map((r,i)=>i===a?{...r,values:o}:r);case"UPDATE_TYPE_AT":const[s,l]=n.payload;return e.map((r,i)=>i===s?{...r,contextName:l}:r)}},_r=(e=[])=>m.useReducer(Mr,e);var Q=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Q||{});const Lr=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})),Nr=d(J)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Tn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),_t=d(Tn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),zr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),jr=d(Ea)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),Wr=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex","& > div":{width:"100%"}})),Lt=d(cn)(()=>({width:"100%"})),Ur=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),qr=d(cn)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Hr=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),xn=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%"}}})),Gr=d(xn)({alignItems:"end",justifyContent:"space-between"}),Yr=d(sn)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),Kr=d(de)(({theme:e})=>({marginTop:e.spacing(-1),marginLeft:e.spacing(-1)})),Jr=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Xr={type:"string",value:""},Qr=({variant:e,variants:n,updateVariant:a,removeVariant:o,apiPayload:s})=>{const[l,r]=m.useState(e.name),[i,p]=m.useState(e.weightType===Q.FIX),[u,g]=m.useState(String(e.weight/10)),[h,f]=m.useState(e.payload||Xr),[S,w]=_r(e.overrides||[]),{context:x}=ht(),[b,C]=m.useState({}),D=y=>{C(v=>({...v,[y]:void 0}))},k=(y,v)=>{C(E=>({...E,[y]:v}))};m.useEffect(()=>{var y;D("percentage"),(y=s.error)!=null&&y.includes("%")&&k("percentage","Total weight must equal 100%")},[s.error]);const $=!e.new,P=n.filter(({id:y,weightType:v})=>y!==e.id&&v===Q.VARIABLE).length>0,F=y=>{const v=y.weightType===Q.VARIABLE,E=n.some(N=>N.weightType===Q.FIX),_=n.filter(N=>N.weightType===Q.VARIABLE).length===1;return E&&_&&v},V=y=>{D("name"),ee(y,e.id)||k("name","A variant with that name already exists for this environment."),r(y.trim())},B=y=>{(y===""||A(y))&&g(y)},q=y=>{M(y)||k("payload","Invalid JSON.")},H=()=>{x.length>0&&w({type:"ADD",payload:{contextName:x[0].name,values:[]}})},Z=y=>!!y.length,ee=(y,v)=>$||!n.some(E=>E.name===y&&E.id!==v),A=y=>{if(!i)return!0;if(y===""||y.match(/\.[0-9]{2,}$/))return!1;const v=Number(y);return v>=0&&v<=100},M=y=>{try{return y.type==="json"&&JSON.parse(y.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:l,weight:Number(i?u:100)*10,weightType:i?Q.FIX:Q.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:S.map(y=>({contextName:y.contextName,values:y.values})).filter(y=>y.values&&y.values.length>0),isValid:Z(l)&&ee(l,e.id)&&A(u)&&M(h)&&!s.error})},[l,i,u,h,S]),m.useEffect(()=>{i||g(String(e.weight/10))},[e.weight]),c(Lr,{"data-testid":"VARIANT",children:[t(Nr,{arrow:!0,title:F(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t(Ee,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>o(e.id),disabled:F(e),children:t(rn,{})})})}),c(Gr,{children:[c(Hr,{children:[t(Tn,{children:"Variant name"}),t(zr,{children:"This will be used to identify the variant in your code"}),t(Lt,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:!!b.name,errorText:b.name,value:l,onChange:y=>V(y.target.value),disabled:$,required:!0})]}),t(T,{condition:P,show:c(Ur,{children:[t(jr,{label:"Custom percentage",control:t(Ra,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:i,onChange:y=>p(y.target.checked)})}),t(qr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:!!b.percentage,errorText:b.percentage,value:u,onChange:y=>B(y.target.value),required:i,disabled:!i,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(Ia,{position:"end",children:"%"})}})]})})]}),c(_t,{children:["Payload",t(at,{tooltip:"Passed along with the the variant object."})]}),c(xn,{children:[t(Yr,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:Jr,onChange:y=>{D("payload"),f(v=>({...v,type:y.target.value}))}}),t(Wr,{children:t(Lt,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:y=>{D("payload"),f(v=>({...v,value:y.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>q(h),error:!!b.payload,errorText:b.payload})})]}),c(_t,{children:["Overrides",t(at,{tooltip:"Here you can specify which users should get this variant."})]}),t(Vr,{overrides:S,overridesDispatch:w}),t("div",{children:t(Kr,{onClick:H,variant:"text",color:"primary","data-testid":"VARIANT_ADD_OVERRIDE_BUTTON",children:"Add override"})})]})};let Fe;const Zr=new Uint8Array(16);function ei(){if(!Fe&&(Fe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Fe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Fe(Zr)}const ti=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Nt={randomUUID:ti};function et(e,n,a){if(Nt.randomUUID&&!n&&!e)return Nt.randomUUID();e=e||{};const o=e.random||(e.rng||ei)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,n){a=a||0;for(let s=0;s<16;++s)n[a+s]=o[s];return n}return Ao(o)}const ni=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})),ai=d(ln,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),oi=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})),si=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ri=d(le)(({theme:e})=>({marginBottom:e.spacing(2)})),ii=d(le)(({theme:e})=>({marginTop:e.spacing(4)})),ci=d("div")({display:"flex",flexDirection:"column"}),li=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),zt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),di=d(we)(({theme:e})=>({margin:e.spacing(4,0)})),ui=d(Da)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),pi=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),gi=d(de)(({theme:e})=>({marginLeft:e.spacing(3)})),hi=({environment:e,open:n,setOpen:a,getApiPayload:o,getCrPayload:s,onConfirm:l})=>{const r=I("projectId"),i=I("featureId"),{uiConfig:p}=Ne(),{context:u}=ht(),{defaultStickiness:g,loading:h}=ka(r),{isChangeRequestConfigured:f}=se(r),{data:S}=ye(r),{changeRequestInReviewOrApproved:w,alert:x}=$a(S),b=(e==null?void 0:e.variants)||[],[C,D]=m.useState([]),[k,$]=m.useState();m.useEffect(()=>{h||D(b.length?b.map(R=>({...R,isValid:!0,new:!1,id:et()})):[{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(C==null?void 0:C.length)>0?C[0].stickiness:g,new:!0,isValid:!1,id:et()}])},[n,h]);const P=(R,G)=>{D(ue=>Ct(ue.map(ke=>ke.id===G?R:ke),1e3))},F=()=>{const R=et();D(G=>[...G,{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(G==null?void 0:G.length)>0?G[0].stickiness:g,new:!0,isValid:!1,id:R}]),$(R)};m.useEffect(()=>{if(k){const R=document.getElementById(`variant-name-input-${k}`);R==null||R.scrollIntoView({behavior:"smooth",block:"center"}),R==null||R.focus({preventScroll:!0}),$(void 0)}},[k]);const V=C.map(({new:R,isValid:G,id:ue,...ke})=>ke),B=o(b,V),q=s(V),H=async R=>{R.preventDefault(),l(V)},Z=()=>y?`curl --location --request POST '${p.unleashUrl}/api/admin/projects/${r}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
1
|
+
import{aB as En,aC as Rn,t as d,r as m,aD as In,aE as Dn,aF as bt,j as t,aG as kn,aH as Fn,E as Gt,aI as I,aJ as z,aK as Bn,h as c,aL as $n,C as T,aM as te,aN as he,aO as X,aP as be,aQ as Pn,aR as ct,aS as xe,aT as Ve,aU as lt,aV as On,aW as Vn,aX as Mn,aY as _n,m as K,aZ as Me,a_ as ye,n as U,T as j,a$ as Ae,b0 as Se,b1 as Ln,b2 as se,b3 as oe,b4 as J,I as Ee,b5 as Nn,b6 as zn,b7 as Re,ah as fe,b8 as $e,b9 as Yt,ba as Ce,bb as ie,as as ce,A as le,bc as Kt,bd as jn,be as Wn,bf as Un,bg as qn,bh as nt,bi as Hn,bj as Gn,F as O,B as Y,bk as Yn,bl as Kn,bm as Jn,bn as Xn,bo as Qn,bp as Zn,bq as ea,br as ta,bs as na,X as aa,b as Jt,d as _e,G as ve,bt as dt,ai as de,bu as oa,bv as ne,a0 as ut,bw as Pe,z as Le,a4 as sa,bx as pt,by as ge,bz as ra,x as Xt,a6 as Ne,bA as ia,bB as ae,bC as ca,bD as la,a3 as da,bE as ua,bF as pa,bG as ga,bH as Qt,bI as ha,bJ as fa,bK as Zt,bL as ma,bM as en,bN as ya,bO as Sa,y as gt,bP as ba,bQ as Ca,bR as ze,bS as va,$ as tn,ao as we,bT as wa,bU as Ta,bV as at,bW as nn,bX as an,bY as re,bZ as ot,b_ as xa,al as on,b$ as sn,ad as ht,am as Aa,c0 as rn,c1 as Ea,c2 as cn,c3 as Ra,c4 as Ia,c5 as ln,c6 as Da,c7 as ka,q as Fa,av as Ba,c8 as pe,c9 as Ct,ca as $a,cb as Pa,cc as Oa,P as ft,o as Va,S as vt,cd as Ma,ce as _a,cf as La,cg as wt,U as dn,ch as Na,f as Ue,g as za,K as ja,M as Wa,N as Ua,O as qa,Q as Ha,R as Ga,ci as Ya,cj as Tt,ck as Ka,cl as un,cm as Ja,an as Xa,cn as xt,co as Qa,cp as Za,cq as eo,cr as to,cs as no,ct as ao,a as oo,cu as so,cv as ro,cw as io,cx as co,cy as lo,cz as uo}from"./index-78d048a4.js";import{C as mt,f as pn,E as po,F as go,V as ho,a as fo,u as mo,b as yo,T as So,c as bo,d as Co,W as vo,e as wo,g as To}from"./FeatureArchiveDialog-42d2cf92.js";import{S as xo}from"./StrategyItemContainer-7b356e23.js";import{u as Ao}from"./stringify-ec884b6d.js";function Eo(e){return En("MuiCardContent",e)}Rn("MuiCardContent",["root"]);const Ro=["className","component"],Io=e=>{const{classes:n}=e;return Fn({root:["root"]},Eo,n)},Do=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),ko=m.forwardRef(function(n,a){const o=In({props:n,name:"MuiCardContent"}),{className:s,component:l="div"}=o,r=Dn(o,Ro),i=bt({},o,{component:l}),p=Io(i);return t(Do,bt({as:l,className:kn(p.root,s),ownerState:i,ref:a},r))}),Fo=ko,Bo=Gt(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),$o=Gt(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"),Po=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Oo=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n);return a.name?t(Po,{children:t(Bn,{title:"Event log",feature:n,displayInline:!0})}):null},Vo=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"}})),Mo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),_o=d("div")({display:"flex",alignItems:"center"}),Lo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),No=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),At=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Et=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),zo=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n),{project:o,description:s,type:l}=a,r=Pn(l);return t(Vo,{children:c(Mo,{children:[c(_o,{"data-loading":!0,children:[t(r,{sx:i=>({marginRight:i.spacing(2),height:"40px",width:"40px",fill:i.palette.primary.contrastText})})," ",c(Lo,{children:[$n(l||"")," toggle"]})]}),c(No,{children:[c(At,{"data-loading":!0,children:["Project: ",o]}),t(T,{condition:!!s,show:c(At,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(Et,{children:[t("p",{children:s}),t(te,{projectId:e,permission:he,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(be,{sx:i=>({color:i.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:c(Et,{children:["No description."," ",t(te,{projectId:e,permission:he,component:X,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(be,{sx:i=>({color:i.palette.primary.contrastText})})})]})})})]})]})})},Rt={lastHourUsage:[],seenApplications:[]},jo=(e,n,a={})=>{const o=async()=>{const g=xe(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Ve("feature metrics"));return h.ok?h.json():Rt},s=`${e}_${n}_metrics`,{data:l,error:r}=ct(s,o,{...a}),[i,p]=m.useState(!r&&!l),u=()=>{lt(s)};return m.useEffect(()=>{p(!r&&!l)},[l,r]),{metrics:l||Rt,error:r,loading:i,refetch:u,FEATURE_METRICS_CACHE_KEY:s}},Wo=e=>({yes:0,no:0,environment:e,timestamp:""}),Uo=(e,n)=>e.map(a=>n.lastHourUsage.find(s=>s.environment===a.name)||Wo(a.name)),qo=e=>(n,a,o)=>(o.revalidateOnFocus=!1,o.revalidateIfStale=!1,o.revalidateOnReconnect=!1,e(n,a,o)),Ho=On(ct,qo),gn=(e,n)=>{const{refetchFeature:a}=z(e,n),o=Vn(e,n),{data:s,error:l,mutate:r}=Ho(["useFeatureImmutable",o],()=>Mn(o)),i=m.useCallback(async()=>{await r(),await a()},[r,a]);return{feature:(s==null?void 0:s.body)||_n,refetchFeature:i,loading:!l&&!s,status:s==null?void 0:s.status,error:l}},yt=(e,n,a)=>{const{setToastData:o,setToastApiError:s}=K(),{addChange:l}=Me(),{refetch:r}=ye(e),[i,p]=m.useState({isOpen:!1}),u=m.useCallback((w,x,b)=>{p({featureName:n,environment:w,fromEnvironment:b,strategy:x,isOpen:!0})},[]),g=m.useCallback((w,x,b)=>{p({featureName:n,environment:w,fromEnvironment:b,strategies:x,isOpen:!0})},[]),h=m.useCallback(()=>{p({isOpen:!1})},[]),f=m.useCallback(async()=>{try{await l(e,i.environment,{feature:i.featureName,action:a,payload:i.strategy}),r(),p({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(w){s(U(w)),p({isOpen:!1})}},[l]),S=m.useCallback(async()=>{try{await Promise.all(i.strategies.map(w=>l(e,i.environment,{feature:i.featureName,action:a,payload:w}))),r(),p({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(w){s(U(w)),p({isOpen:!1})}},[l]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:f,onChangeRequestAddStrategiesConfirm:S,changeRequestDialogDetails:i}},Go=({payload:e,fromEnvironment:n,environment:a})=>c(j,{children:[c("strong",{children:["Copy ",Ae((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Yo=({environmentId:e,environments:n,strategy:a})=>{const o=I("projectId"),s=I("featureId"),[l,r]=m.useState(null),i=!!l,{addStrategyToFeature:p}=Se(),{setToastData:u,setToastApiError:g}=K(),{refetchFeature:h}=z(o,s),{refetchFeature:f}=gn(o,s),S=()=>{r(null)},w=Ln(o),{isChangeRequestConfigured:x}=se(o),{changeRequestDialogDetails:b,onChangeRequestAddStrategyClose:C,onChangeRequestAddStrategy:D,onChangeRequestAddStrategyConfirm:k}=yt(o,s,"addStrategy"),$=async F=>{const{id:V,...B}={...a,targetEnvironment:F};if(x(F)){await D(F,{id:V,...B},e);return}try{await p(o,s,F,a),h(),f(),u({title:"Strategy created",text:`Successfully copied a strategy to ${F}`,type:"success"})}catch(q){g(U(q))}S()},P=n.some(F=>w(oe,F));return c("div",{children:[t(mt,{isOpen:b.isOpen,onClose:C,environment:b==null?void 0:b.environment,onConfirm:k,messageComponent:t(Go,{fromEnvironment:b.fromEnvironment,payload:b.strategy})}),t(J,{title:`Copy to another environment${P?"":" (Access denied)"}`,children:t("div",{children:t(Ee,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:F=>{r(F.currentTarget)},"data-testid":Nn,disabled:!P,children:t(zn,{})})})}),t(Re,{id:"basic-menu",anchorEl:l,open:i,onClose:S,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(F=>{const V=w(oe,F);return t(J,{title:V?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(fe,{onClick:()=>$(F),disabled:!V,children:[t(T,{condition:!V,show:t($e,{children:t(Yt,{fontSize:"small"})})}),c(Ce,{children:["Copy to ",F]})]})})},F)})})]})},hn=()=>t(le,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Ko=({onRemove:e,onClose:n,isOpen:a})=>t(ie,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(hn,{})}),Jo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Xo=({onRemove:e,onClose:n,isOpen:a})=>c(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(hn,{}),t(Jo,{children:t(j,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(j,{fontWeight:"bold",children:"Remove strategy"})]}),Qo=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{deleteStrategyFromFeature:s}=Se(),{setToastData:l,setToastApiError:r}=K(),i=ce(),{refetchFeature:p}=z(e,n);return async g=>{try{g.preventDefault(),await s(e,n,a,o),l({title:"Strategy deleted",type:"success"}),p(),i(Kt(e,n))}catch(h){r(U(h))}}},Zo=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{addChange:s}=Me(),{refetch:l}=ye(e),{setToastData:r,setToastApiError:i}=K();return async u=>{try{u.preventDefault(),await s(e,a,{action:"deleteStrategy",feature:n,payload:{id:o}}),r({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(U(g))}}},es=({projectId:e,featureId:n,environmentId:a,strategyId:o,text:s,isOpen:l,onClose:r})=>{const{isChangeRequestConfigured:i}=se(e),p=Qo({featureId:n,projectId:e,strategyId:o,environmentId:a}),u=Zo({featureId:n,projectId:e,strategyId:o,environmentId:a});return i(a)?t(Xo,{isOpen:l,onClose:()=>r(),onRemove:async g=>{await u(g),r()}}):t(Ko,{isOpen:l,onClose:()=>r(),onRemove:p})},ts=({projectId:e,environmentId:n,featureId:a,strategy:o})=>{const{refetchFeature:s}=z(e,a),{setStrategyDisabledState:l}=Se(),{setToastData:r,setToastApiError:i}=K(),p=u=>async()=>{try{await l(e,a,n,o.id,!u),r({title:`Strategy ${u?"enabled":"disabled"}`,type:"success"}),s()}catch(g){i(U(g))}};return{onDisable:p(!1),onEnable:p(!0)}},ns=({projectId:e,environmentId:n,featureId:a,strategy:o})=>{const{addChange:s}=Me(),{refetch:l}=ye(e),{setToastData:r,setToastApiError:i}=K(),p=u=>async()=>{try{await s(e,n,{action:"updateStrategy",feature:a,payload:{...o,disabled:!u}}),r({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(U(g))}};return{onSuggestDisable:p(!1),onSuggestEnable:p(!0)}},as=({isOpen:e,onClose:n,...a})=>{var S;const{projectId:o,environmentId:s}=a,{isChangeRequestConfigured:l}=se(o),r=l(s),{onSuggestEnable:i,onSuggestDisable:p}=ns({...a}),{onEnable:u,onDisable:g}=ts({...a}),h=!!((S=a.strategy)!=null&&S.disabled);return t(ie,{title:r?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:r?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:w=>{w.preventDefault(),r?h?i():p():h?u():g(),n()},onClose:()=>n(),children:t(T,{condition:r,show:t(jn,{environment:s}),elseShow:c(le,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var St={},os=Un;Object.defineProperty(St,"__esModule",{value:!0});var fn=St.default=void 0,ss=os(Wn()),rs=qn,is=(0,ss.default)((0,rs.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"}),"Delete");fn=St.default=is;const cs=({projectId:e,strategy:n,featureId:a,environmentId:o})=>{const[s,l]=m.useState(null),[r,i]=m.useState(!1),[p,u]=m.useState(!1),g=!!s,h=x=>{l(x.currentTarget)},f=x=>{l(null),x.stopPropagation()},S=nt(Hn,e,o),w=nt(Gn,e,o);return c(O,{children:[t(Y,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(J,{title:"More actions",children:t(Ee,{onClick:h,size:"small","aria-controls":g?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":g?"true":void 0,"data-testid":Yn,children:t(Kn,{sx:{width:32,height:32}})})})}),c(Re,{anchorEl:s,id:"actions-menu",open:g,onClose:f,onClick:f,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Jn,children:[t(J,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:c(fe,{disabled:!S,onClick:()=>i(!0),children:[t($e,{children:n.disabled?t(Xn,{}):t(Qn,{})}),t(Ce,{children:n.disabled?"Enable":"Disable"})]})}),t(J,{title:"Remove strategy",arrow:!0,placement:"left",children:c(fe,{disabled:!w,onClick:()=>u(!0),"data-testid":Zn,children:[t($e,{children:t(fn,{})}),t(Ce,{children:"Remove"})]})})]}),t(as,{isOpen:r,onClose:()=>i(!1),projectId:e,featureId:a,environmentId:o,strategy:n}),t(es,{isOpen:p,onClose:()=>u(!1),projectId:e,featureId:a,environmentId:o,strategyId:n.id})]})},ls=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:o,otherEnvironments:s,orderNumber:l,headerChildren:r})=>{const i=I("projectId"),p=I("featureId"),u=ea(i,p,e,n.id);return t(xo,{strategy:n,onDragStart:a,onDragEnd:o,orderNumber:l,actions:c(O,{children:[r,t(T,{condition:!!(s&&(s==null?void 0:s.length)>0),show:()=>t(Yo,{environmentId:e,environments:s,strategy:n})}),t(te,{permission:ta,environmentId:e,projectId:i,component:X,to:u,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(be,{})}),t(cs,{projectId:i,featureId:p,environmentId:e,strategy:n})]}),children:t(na,{strategy:n})})},ds=(e,n,a,o)=>{const{data:s}=ye(e),l=s==null?void 0:s.find(p=>p.environment===a),r=l==null?void 0:l.features.find(p=>p.name===n);return r==null?void 0:r.changes.find(p=>p.action==="updateStrategy"||p.action==="deleteStrategy"?p.payload.id===o:!1)},us=({strategy:e,index:n,environmentName:a,otherEnvironments:o,isDragging:s,onDragStartRef:l,onDragOver:r,onDragEnd:i})=>{const p=I("projectId"),u=I("featureId"),g=m.useRef(null),h=ds(p,u,a,e.id);return c(Y,{ref:g,onDragOver:r(g,n),sx:{opacity:s?"0.5":"1"},children:[t(T,{condition:n>0,show:t(aa,{text:"OR"})}),t(ls,{strategy:e,environmentId:a,otherEnvironments:o,onDragStart:l(g,n),onDragEnd:i,orderNumber:n+1,headerChildren:t(ps,{change:h})})]},e.id)},ps=({change:e})=>{const n=Jt();return _e(n.breakpoints.down("sm"))?null:c(Y,{sx:{mr:1.5},children:[t(T,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(ve,{color:"warning",children:"Modified in draft"})}),t(T,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(ve,{color:"error",children:"Deleted in draft"})})]})},gs=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}})),hs=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})),mn=({children:e})=>t(gs,{children:t(hs,{children:e})}),fs=({environmentId:e,environments:n,onClick:a})=>{const o=I("projectId"),[s,l]=m.useState(null),r=!!s,{hasAccess:i}=m.useContext(dt),p=n.some(u=>i(oe,o,u));return c("div",{children:[t(J,{title:p?"":"(Access denied)",children:t("div",{children:t(de,{id:`copy-all-strategies-${e}`,"aria-controls":r?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":r?"true":void 0,onClick:u=>{l(u.currentTarget)},disabled:!p,variant:"outlined",children:"Copy from another environment"})})}),t(Re,{id:"basic-menu",anchorEl:s,open:r,onClose:()=>{l(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=i(oe,o,u);return t(J,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(fe,{onClick:()=>a(u),disabled:!g,children:[t(T,{condition:!g,show:t($e,{children:t(Yt,{fontSize:"small"})})}),c(Ce,{children:["Copy from ",u]})]})})},u)})})]})},ms=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),ys=({payload:e,fromEnvironment:n,environment:a})=>c(ms,{children:[t(j,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(o=>c(j,{children:[c("strong",{children:[Ae((o==null?void 0:o.name)||"")," strategy"," "]})," "]})),c(j,{children:["from ",n," to ",a]})]}),Ss=({payload:e,environment:n})=>c(O,{children:[t(j,{component:"span",children:"Add "}),c("strong",{children:[Ae((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),bs=d(oa)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),It=({title:e,children:n,featureId:a,projectId:o,environmentId:s,strategy:l,Icon:r,onAfterAddStrategy:i})=>{const{addStrategyToFeature:p}=Se(),{setToastApiError:u}=K(),{isChangeRequestConfigured:g}=se(o),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:f,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategyClose:w}=yt(o,a,"addStrategy");return c(O,{children:[t(bs,{variant:"outlined",children:c(Fo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(j,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(j,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(Y,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(ne,{permission:oe,projectId:o,environmentId:s,variant:"outlined",size:"small",onClick:async()=>{try{g(s)?f(s,l):(await p(o,a,s,l),i())}catch(b){u(U(b))}},children:"Use template"})})]})}),t(mt,{isOpen:h.isOpen,onClose:w,environment:h==null?void 0:h.environment,onConfirm:S,messageComponent:t(Ss,{environment:s,payload:h.strategy})})]})},Cs=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}})),vs=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ws=d(ut)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Ts=d(X)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),qe=({projectId:e,featureId:n,environmentId:a,strategy:o,defaultStrategy:s})=>{const l=Pe(o.name),r=Ae(o.name),{trackEvent:i}=Le(),p=pn(e,n,a,o.name,s);return c(Ts,{to:p,onClick:()=>{i("strategy-add",{props:{buttonTitle:o.displayName||r}})},children:[t(Cs,{children:t(l,{})}),c("div",{children:[t(ws,{text:o.displayName||r,maxWidth:"200",maxLength:25}),t(vs,{children:o.description})]})]})},He=d(j)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),yn=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:o}=sa(),s=o.filter(i=>!i.deprecated&&!i.editable),l=o.filter(i=>!i.deprecated&&i.editable),r={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return c(pt,{dense:!0,children:[c(O,{children:[c(He,{color:"textSecondary",children:[a," environment default strategy"]}),t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:r,defaultStrategy:!0})},r.name)]}),t(He,{color:"textSecondary",children:"Predefined strategy types"}),s.map(i=>t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name)),t(T,{condition:l.length>0,show:c(O,{children:[t(He,{color:"textSecondary",children:"Custom strategies"}),l.map(i=>t(ge,{children:t(qe,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name))]})})]})},xs=d(ne)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),st=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,size:l,matchWidth:r})=>{const[i,p]=m.useState(),u=ce(),{trackEvent:g}=Le(),h=!!i,f=h?"FeatureStrategyMenuPopover":void 0,S=()=>{p(void 0)},w=C=>{g("strategy-add",{props:{buttonTitle:e}}),u(b)},x=C=>{p(C.currentTarget)},b=pn(n,a,o,"flexibleRollout",!0);return c("div",{onClick:C=>C.stopPropagation(),children:[t(ne,{permission:oe,projectId:n,environmentId:o,onClick:w,"aria-labelledby":f,variant:s,size:l,sx:{minWidth:r?"282px":"auto"},children:e}),t(xs,{permission:oe,projectId:n,environmentId:o,onClick:x,"aria-labelledby":f,variant:"outlined",size:l,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(ra,{sx:C=>({margin:C.spacing(.25,0)})})}),t(Xt,{id:f,open:h,anchorEl:i,onClose:S,onClick:S,PaperProps:{sx:C=>({paddingBottom:C.spacing(1)})},children:t(yn,{projectId:n,featureId:a,environmentId:o})})]})},rt=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,matchWidth:l})=>{const[r,i]=m.useState(),p=!!r,u=p?"FeatureStrategyMenuPopover":void 0,g=()=>{i(void 0)};return c("div",{onClick:f=>f.stopPropagation(),children:[t(ne,{permission:oe,projectId:n,environmentId:o,onClick:f=>{i(f.currentTarget)},"aria-labelledby":u,variant:s,sx:{minWidth:l?"282px":"auto"},children:e}),t(Xt,{id:u,open:p,anchorEl:r,onClose:g,onClick:g,children:t(yn,{projectId:n,featureId:a,environmentId:o})})]})},As=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Es=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Rs=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),Is=({projectId:e,featureId:n,environmentId:a})=>{var $;const{addStrategyToFeature:o}=Se(),{setToastData:s,setToastApiError:l}=K(),{refetchFeature:r}=z(e,n),{refetchFeature:i}=gn(e,n),{feature:p}=z(e,n),u=p==null?void 0:p.environments.filter(P=>P.name!==a&&P.strategies&&P.strategies.length>0),{isChangeRequestConfigured:g}=se(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:f,onChangeRequestAddStrategiesConfirm:S,onChangeRequestAddStrategyClose:w}=yt(e,n,"addStrategy"),{uiConfig:x}=Ne(),b=($=x==null?void 0:x.flags)==null?void 0:$.strategySplittedButton,C=(P=!1)=>{r(),i(),s({title:P?"Strategies created":"Strategy created",text:P?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},D=async P=>{var V;const F=((V=u==null?void 0:u.find(B=>B.name===P))==null?void 0:V.strategies)||[];if(g(a)){await f(a,F,P);return}try{await Promise.all(F.map(B=>{const{id:q,...H}={...B,environment:a};return o(e,n,a,H)})),C(!0)}catch(B){l(U(B))}},k=u&&u.length>0;return c(O,{children:[t(mt,{isOpen:h.isOpen,onClose:w,environment:h==null?void 0:h.environment,onConfirm:S,messageComponent:t(ys,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(As,{children:[t(Es,{children:"You have not defined any strategies yet."}),c(Rs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(X,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Y,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(T,{condition:!!b,show:t(st,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:k}),elseShow:t(rt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:k})}),t(T,{condition:k,show:t(fs,{environmentId:a,environments:u.map(P=>P.name),onClick:D})})]}),t(T,{condition:b===!1,show:c(O,{children:[t(Y,{sx:{width:"100%",mt:3},children:t(mn,{children:"Or use a strategy template"})}),c(Y,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(It,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:C,Icon:Pe("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(It,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:C,Icon:Pe("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:p.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})})]})]})},Ds=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ks=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Fs=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const o=I("projectId"),s=I("featureId"),{setStrategiesSortOrder:l}=Se(),{setToastData:r,setToastApiError:i}=K(),{refetchFeature:p}=z(o,s),[u,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,f]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const S=async C=>{try{await l(o,s,e.name,C),p(),r({title:"Order of strategies updated",type:"success"})}catch(D){i(U(D))}},w=(C,D)=>k=>{var $;f({id:u[D].id,index:D,height:(($=C.current)==null?void 0:$.offsetHeight)||0}),C!=null&&C.current&&(k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/html",C.current.outerHTML),k.dataTransfer.setDragImage(C.current,20,20))},x=C=>(D,k)=>$=>{if(h===null||D.current===null||h.index===k||C===h.id)return;const{top:P,bottom:F}=D.current.getBoundingClientRect(),V=$.clientY-P<h.height,B=F-$.clientY<h.height,q=h.index>k;if(V&&q||B&&!q){const H=[...u],Z=H.splice(h.index,1)[0];H.splice(k,0,Z),g(H),f({...h,index:k})}},b=()=>{f(null),S(u.map((C,D)=>({id:C.id,sortOrder:D})))};return t(Ds,{children:c(ks,{children:[t(T,{condition:u.length>0&&n,show:()=>t(le,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(T,{condition:u.length>0,show:t(O,{children:u.map((C,D)=>t(us,{strategy:C,index:D,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===C.id,onDragStartRef:w,onDragOver:x(C.id),onDragEnd:b},C.id))}),elseShow:t(Is,{projectId:o,featureId:s,environmentId:e.name})})]})})},Sn=(e,n)=>e===0?0:Math.round(n/e*100);var je={},We={};Object.defineProperty(We,"__esModule",{value:!0});We.defaultOptions=void 0;We.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var me={};Object.defineProperty(me,"__esModule",{value:!0});me.roundTo=me.parseValue=void 0;function Bs(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}me.parseValue=Bs;function $s(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))}me.roundTo=$s;Object.defineProperty(je,"__esModule",{value:!0});je.millify=void 0;const Ge=We,Dt=me,kt=1e3;function*Ft(e){let n=kt;for(;;){const a=e/n;if(a<1)return;yield a,n*=kt}}function bn(e,n){var a;const o=n?Object.assign(Object.assign({},Ge.defaultOptions),n):Ge.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let s;try{s=Dt.parseValue(e)}catch(S){return S instanceof Error&&console.warn(`WARN: ${S.message} (millify)`),String(e)}const l=s<0?"-":"";s=Math.abs(s);let r=0;for(const S of Ft(s))s=S,r+=1;if(r>=o.units.length)return e.toString();let p=Dt.roundTo(s,o.precision);for(const S of Ft(p))p=S,r+=1;const u=(a=o.units[r])!==null&&a!==void 0?a:"",g=o.lowercase?u.toLowerCase():u,h=o.space?" ":"",f=p.toString().replace(Ge.defaultOptions.decimalSeparator,o.decimalSeparator);return`${l}${f}${h}${g}`}je.millify=bn;var Ps=je.default=bn;const Oe=({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 l=t("span",{"data-testid":ia,children:o});return t(T,{condition:s,show:t(J,{title:e.toLocaleString(),arrow:!0,children:l}),elseShow:l})},Ye=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Ke=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),Je=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),Xe=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 l=a===1?"in the last hour":`in the last ${a} hours`;return c(ae,{container:!0,spacing:2,id:o,"aria-describedby":s,"aria-label":"Feature metrics summary",component:"section",children:[t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Exposure"}),t(Je,{children:t(Oe,{value:e})}),c(Xe,{children:["Total exposure of the feature in the environment"," ",l,"."]})]})}),t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Exposure %"}),c(Je,{children:[Sn(e+n,e),"%"]}),c(Xe,{children:["% total exposure of the feature in the environment"," ",l,"."]})]})}),t(ae,{item:!0,xs:12,sm:4,children:c(Ye,{children:[t(Ke,{children:"Requests"}),t(Je,{children:t(Oe,{value:e+n})}),c(Xe,{children:["Total requests for the feature in the environment"," ",l,"."]})]})})]})},Os=({environmentMetric:e})=>e?c(O,{children:[t(mn,{children:"Feature toggle exposure"}),t("div",{children:t(Cn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Bt=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),$t=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Pt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Ot=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Vs=d(ca)(({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"}})),_s=({environmentMetric:e,disabled:n=!1})=>{const a=la();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(Bt,{children:[c($t,{children:[c(Pt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[s,"%"]}),c(Ot,{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(Vs,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Bt,{children:[c($t,{children:[c(Pt,{children:[s,"%"]}),c(Ot,{children:["The feature has been requested"," ",c("b",{children:[t(Oe,{value:o})," times"]})," ","and exposed"," ",c("b",{children:[t(Oe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(Ms,{"data-loading":!0,children:t(da,{percentage:s,size:"3rem"})})]})},Ls=({strategyName:e})=>{const n=Pe(e);return t(J,{title:Ae(e),arrow:!0,children:t(Ns,{children:t(n,{})})})},Ns=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)}})),zs=({strategies:e})=>e!=null&&e.length?t(js,{"aria-label":"Feature strategies",children:e.map(n=>t(Ws,{children:t(Ls,{strategyName:n.name})},n.id))}):null,js=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Ws=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Us=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})),qs=d(ua)({boxShadow:"none",background:"none"}),Hs=d(pa)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Gs=d(ga,{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)}})),Ys=d(Fs)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ks=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})),Js=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Xs=d(po)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Qs=d(ut)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Zs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),er=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),[e.breakpoints.down(560)]:{flexDirection:"column"}})),tr=({env:e})=>{var h,f;const n=I("projectId"),a=I("featureId"),{metrics:o}=jo(n,a),{feature:s}=z(n,a),{value:l}=Qt(),{uiConfig:r}=Ne(),i=(h=r==null?void 0:r.flags)==null?void 0:h.strategySplittedButton,u=Uo(s==null?void 0:s.environments,o).find(S=>S.environment===e.name),g=s==null?void 0:s.environments.find(S=>S.name===e.name);return t(T,{condition:!new Set(l.hiddenEnvironments).has(e.name),show:t(Us,{enabled:e.enabled,children:c(qs,{"data-testid":`${ha}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(Hs,{expandIcon:t(fa,{titleAccess:"Toggle"}),children:[c(Ks,{"data-loading":!0,enabled:e.enabled,children:[c(Js,{children:[t(Xs,{enabled:e.enabled}),t("div",{children:t(Qs,{text:e.name,maxWidth:"100",maxLength:15})}),t(T,{condition:!e.enabled,show:t(ve,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),t(T,{condition:!!i,show:t(er,{children:t(st,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"})}),elseShow:c(Zs,{children:[t(rt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(zs,{strategies:g==null?void 0:g.strategies})]})})]}),t(_s,{environmentMetric:u,disabled:!e.enabled})]}),c(Gs,{enabled:e.enabled,children:[t(Ys,{featureEnvironment:g,isDisabled:!e.enabled,otherEnvironments:s==null?void 0:s.environments.map(({name:S})=>S).filter(S=>S!==e.name)}),t(T,{condition:(((f=g==null?void 0:g.strategies)==null?void 0:f.length)||0)>0,show:c(O,{children:[t(Y,{sx:{display:"flex",justifyContent:"center",py:1},children:t(T,{condition:!!i,show:t(st,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name}),elseShow:t(rt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})})}),t(Os,{environmentMetric:u})]})})]})]})})})},nr=()=>{const e=I("projectId"),n=I("featureId"),{feature:a}=z(e,n);if(!a)return null;const{environments:o}=a;return t(O,{children:o==null?void 0:o.map(s=>t(tr,{env:s},s.name))})},ar=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),or=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),sr=({feature:e,header:n})=>{const{locationSettings:a}=Zt();return c(ar,{children:[n,c("div",{"data-loading":!0,children:[t(or,{children:"Created at:"}),t("span",{children:ma(en(e.createdAt),a.locale)})]})]})},rr=d(Ee,{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}})),ir=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(rr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(T,{condition:n.has(e.name),show:t(ya,{}),elseShow:t(Sa,{})})}),cr=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),lr=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),dr=({environment:e,callback:n,showInfoBox:a,children:o,hiddenEnvironments:s,setHiddenEnvironments:l})=>{const{name:r,enabled:i}=e,p=I("projectId"),u=I("featureId"),{feature:g,refetchFeature:h}=z(p,u),f=c(O,{children:[" ",c("span",{"data-loading":!0,children:[i?"enabled":"disabled"," in"]})," ",t(ut,{text:r,maxWidth:"120",maxLength:15})]}),S=()=>{h(),n&&n()};return c(cr,{children:[c(lr,{children:[t(go,{featureId:g.name,projectId:p,environmentName:e.name,onToggle:S,onError:a,value:i}),o??f]}),t(ir,{environment:e,hiddenEnvironments:s,setHiddenEnvironments:l})]})},ur=d("div")(({theme:e})=>({padding:e.spacing(3)})),pr=d("div")(()=>({display:"flex",flexDirection:"column"})),gr=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),hr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Vt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),fr=d(gt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),mr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:o})=>{const[s,l]=m.useState(!1),[r,i]=m.useState(""),p=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return c(ur,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],f=h.length>0&&c(O,{children:[t(Vt,{}),t(J,{title:"View variants",arrow:!0,describeChild:!0,children:t(fr,{component:X,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),S=u.enabled&&h.length===0&&p;return t(dr,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:o,showInfoBox:()=>{i(u.name),l(!0)},children:c(pr,{children:[t(gr,{children:u.name}),c(hr,{children:[g,f,t(T,{condition:S,show:c(O,{children:[t(Vt,{}),t(ho,{})]})})]})]})},u.name)}),t(fo,{open:s,onClose:()=>l(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},vn=(e,n={})=>{const a=async()=>{const u=xe(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Ve("Tags"))).json()},o=`api/admin/features/${e}/tags`,{data:s,error:l}=ba(!!e,{tags:[]},o,a,n),[r,i]=m.useState(!l&&!s),p=()=>{lt(o)};return m.useEffect(()=>{i(!l&&!s)},[s,l]),{tags:(s==null?void 0:s.tags)||[],error:l,loading:r,refetch:p}},yr=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),Qe=e=>e.map(n=>({title:n.value})),Mt=(e,n)=>e.map(a=>({value:a.title,type:n})),wn=({open:e,setOpen:n})=>{const{tagTypes:a}=Ca(),o=I("featureId"),{createTag:s}=mo(),{updateFeatureTags:l,loading:r}=ze(),{tags:i,refetch:p,loading:u}=vn(o),{setToastData:g}=K(),h=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[f,S]=m.useState(h),w=r||u,[x,b]=m.useState(0),{trackEvent:C}=Le(),[D,k]=m.useState(Qe(i.filter(v=>v.type===f.name))),{tags:$,refetch:P}=yo(f.name),F=m.useMemo(()=>Qe($),[$]);m.useEffect(()=>{i&&f&&k(Qe(i.filter(v=>v.type===f.name)))},[JSON.stringify(i),f]);const V=()=>{n(!1),k([])};function B(v,E){const _=v.filter(L=>L.type===f.name).filter(L=>!E.find(W=>L.value===W.value&&L.type===W.type)),N=E.filter(L=>L.type===f.name).filter(L=>!v.find(W=>L.value===W.value&&L.type===W.type));return b(_.length+N.length),{added:_,removed:N}}const q=v=>v.filter(E=>!E.title.startsWith("Create")),H=async(v,E)=>{try{await l(o,{addedTags:v,removedTags:E}),await p()}catch(_){const N=U(_);g({type:"error",title:"Failed to add tag",text:N,confetti:!1})}},Z=(v,E)=>{let _="We successfully";return v>0&&(_=_.concat(` added ${v} new tag${v>1?"s":""}`)),v>0&&E>0&&(_=_.concat(" and ")),E>0&&(_=_.concat(` removed ${E} tag${E>1?"s":""}`)),_},ee=async v=>{v.preventDefault();const E=Mt(q(D),f.name),{added:_,removed:N}=B(E,i);x>0&&(await H(_,N),x>1&&C("suggest_tags",{props:{eventType:"multiple_tags_added"}}),x>0&&g({type:"success",title:`Updated tag${_.length>1?"s":""} to toggle`,text:Z(_.length,N.length),confetti:!0})),b(0),k([]),n(!1)},A=(v,E)=>{E!=null&&typeof E!="string"&&(v.preventDefault(),S(E),k([]),b(0))},M=(v,E,_)=>{const N=va(E);_==="selectOption"&&E.forEach((W,Ie)=>{if(typeof W!="string"&&W.inputValue&&W.inputValue!==""){const De={value:W.inputValue,type:f.name};s(De).then(()=>{C("suggest_tags",{props:{eventType:"tag_created"}}),P()}),W.title=W.inputValue,W.inputValue="",N[Ie]=W}});const L=Mt(q(N),f.name);B(L,i),k(N)},y="add-tag-form";return t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:ee,disabledPrimaryButton:w||x===0,onClose:V,formId:y,children:c(O,{children:[t(j,{paragraph:!0,sx:{marginBottom:v=>v.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:y,onSubmit:ee,children:c(yr,{children:[t(So,{options:a,value:f,onChange:A}),t(bo,{options:F,existingTags:i,tagType:f,selectedOptions:D,onChange:M})]})})]})})},Sr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),br=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Cr=d(tn)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),vr=d(we)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),wr=d(de)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Tr=({feature:e,header:n})=>{const{tags:a,refetch:o}=vn(e.name),{deleteTagFromFeature:s}=ze(),[l,r]=m.useState(!1),[i,p]=m.useState(!1),[u,g]=m.useState(),{setToastData:h,setToastApiError:f}=K(),{hasAccess:S}=m.useContext(dt),w=S(he,e.project),x=async()=>{if(u)try{await s(e.name,u.type,u.value),o(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(b){f(U(b))}};return c(Sr,{children:[n,t(br,{children:a.map(b=>{const C=`${b.type}:${b.value}`;return t(Cr,{label:C,deleteIcon:t(wa,{titleAccess:"Remove"}),onDelete:w?()=>{p(!0),g(b)}:void 0},C)})}),t(T,{condition:w,show:c(O,{children:[t(T,{condition:a.length>0,show:t(vr,{})}),t(wr,{"data-loading":!0,variant:"outlined",startIcon:t(Ta,{}),onClick:()=>r(!0),children:"Add new tag"})]})}),t(wn,{open:l,setOpen:r}),c(ie,{open:i,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{p(!1),g(void 0)},onClick:()=>{p(!1),x(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},xr=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"}})),Ze=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}})),Ar=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=I("projectId"),o=I("featureId"),{feature:s}=z(a,o);return c(xr,{children:[t(mr,{header:c(Ze,{"data-loading":!0,children:["Enabled in environments (",s.environments.filter(({enabled:l})=>l).length,")",t(at,{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(we,{}),t(sr,{header:t(Ze,{"data-loading":!0,children:"Feature toggle details"}),feature:s}),t(we,{}),t(Tr,{header:t(Ze,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:s})]})},Er=()=>{const{trackEvent:e}=Le(),{value:n,setValue:a}=Qt(),[o,s]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:o,setHiddenEnvironments:r=>{a(i=>{const p=new Set(i.hiddenEnvironments);return p.has(r)?(p.delete(r),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(p.add(r),e("hidden_environment",{props:{eventType:"environment hidden"}})),s(p),{...n,hiddenEnvironments:p}})}}},Rr=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Ir=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),Dr=()=>{const e=ce(),n=I("projectId"),a=I("featureId"),o=Kt(n,a),{hiddenEnvironments:s,setHiddenEnvironments:l}=Er(),r=()=>e(o);return nn(a),c(Rr,{children:[c("div",{children:[t(zo,{}),t(Ar,{hiddenEnvironments:s,setHiddenEnvironments:l})]}),t(Ir,{children:t(nr,{})}),c(an,{children:[t(re,{path:"strategies/create",element:t(ot,{label:"Create feature strategy",onClose:r,open:!0,children:t(Co,{})})}),t(re,{path:"strategies/edit",element:t(ot,{label:"Edit feature strategy",onClose:r,open:!0,children:t(xa,{})})})]})]})},kr=({values:e=[],updateValues:n,placeholder:a="",error:o,...s})=>{const l=i=>{const u=i.target.value.split(/,\s?/).map(g=>g.trim());n(u)},r=i=>{if(i.key==="Backspace"){const p=i.target.value;if(p.endsWith(", ")){i.preventDefault();const u=p.slice(0,-2);n(u.split(/,\s*/))}}};return t(on,{...s,error:o,placeholder:a,value:e?e.join(", "):"",onKeyDown:r,onChange:l,style:{width:"100%"},variant:"outlined",size:"small"})},Fr=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"}}})),Br=d(sn)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),$r=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),Pr=d(kr)(()=>({width:"100%"})),Or=d(on)(()=>({width:"100%"})),Vr=({overrides:e,overridesDispatch:n})=>{const{context:a}=ht(),o=a.map(({name:r})=>({key:r,label:r})),s=r=>i=>{n({type:"UPDATE_VALUES_AT",payload:[r,i]})},l=r=>(i,p)=>{i==null||i.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[r,p||[]]})};return t(O,{children:e.map((r,i)=>{var h;const p=a.find(({name:f})=>f===r.contextName),u=((h=p==null?void 0:p.legalValues)==null?void 0:h.map(({value:f})=>f))||[],g=r.values.filter(f=>u.includes(f));return c(Fr,{children:[t(Br,{id:"override-context-name",name:"contextName",label:"Context Field","data-testid":"context_field",value:r.contextName,options:o,onChange:f=>n({type:"UPDATE_TYPE_AT",payload:[i,f.target.value]})}),c($r,{children:[t(T,{condition:!!(u&&u.length>0),show:t(Aa,{multiple:!0,id:`override-select-${i}`,isOptionEqualToValue:(f,S)=>f===S,options:u,onChange:l(i),getOptionLabel:f=>f,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:f=>t(Or,{...f,variant:"outlined",label:"Legal values"})}),elseShow:t(Pr,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:r.values,updateValues:s(i),"data-testid":"OVERRIDE_VALUES"})}),t(J,{title:"Remove",arrow:!0,children:t(Ee,{onClick:f=>{f.preventDefault(),n({type:"REMOVE",payload:i})},children:t(rn,{})})})]})]},`override=${i}`)})})},Mr=(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,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,o]=n.payload;return e.map((r,i)=>i===a?{...r,values:o}:r);case"UPDATE_TYPE_AT":const[s,l]=n.payload;return e.map((r,i)=>i===s?{...r,contextName:l}:r)}},_r=(e=[])=>m.useReducer(Mr,e);var Q=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(Q||{});const Lr=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})),Nr=d(J)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Tn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),_t=d(Tn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),zr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),jr=d(Ea)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),Wr=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex","& > div":{width:"100%"}})),Lt=d(cn)(()=>({width:"100%"})),Ur=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),qr=d(cn)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Hr=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),xn=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%"}}})),Gr=d(xn)({alignItems:"end",justifyContent:"space-between"}),Yr=d(sn)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),Kr=d(de)(({theme:e})=>({marginTop:e.spacing(-1),marginLeft:e.spacing(-1)})),Jr=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Xr={type:"string",value:""},Qr=({variant:e,variants:n,updateVariant:a,removeVariant:o,apiPayload:s})=>{const[l,r]=m.useState(e.name),[i,p]=m.useState(e.weightType===Q.FIX),[u,g]=m.useState(String(e.weight/10)),[h,f]=m.useState(e.payload||Xr),[S,w]=_r(e.overrides||[]),{context:x}=ht(),[b,C]=m.useState({}),D=y=>{C(v=>({...v,[y]:void 0}))},k=(y,v)=>{C(E=>({...E,[y]:v}))};m.useEffect(()=>{var y;D("percentage"),(y=s.error)!=null&&y.includes("%")&&k("percentage","Total weight must equal 100%")},[s.error]);const $=!e.new,P=n.filter(({id:y,weightType:v})=>y!==e.id&&v===Q.VARIABLE).length>0,F=y=>{const v=y.weightType===Q.VARIABLE,E=n.some(N=>N.weightType===Q.FIX),_=n.filter(N=>N.weightType===Q.VARIABLE).length===1;return E&&_&&v},V=y=>{D("name"),ee(y,e.id)||k("name","A variant with that name already exists for this environment."),r(y.trim())},B=y=>{(y===""||A(y))&&g(y)},q=y=>{M(y)||k("payload","Invalid JSON.")},H=()=>{x.length>0&&w({type:"ADD",payload:{contextName:x[0].name,values:[]}})},Z=y=>!!y.length,ee=(y,v)=>$||!n.some(E=>E.name===y&&E.id!==v),A=y=>{if(!i)return!0;if(y===""||y.match(/\.[0-9]{2,}$/))return!1;const v=Number(y);return v>=0&&v<=100},M=y=>{try{return y.type==="json"&&JSON.parse(y.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:l,weight:Number(i?u:100)*10,weightType:i?Q.FIX:Q.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:S.map(y=>({contextName:y.contextName,values:y.values})).filter(y=>y.values&&y.values.length>0),isValid:Z(l)&&ee(l,e.id)&&A(u)&&M(h)&&!s.error})},[l,i,u,h,S]),m.useEffect(()=>{i||g(String(e.weight/10))},[e.weight]),c(Lr,{"data-testid":"VARIANT",children:[t(Nr,{arrow:!0,title:F(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t(Ee,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>o(e.id),disabled:F(e),children:t(rn,{})})})}),c(Gr,{children:[c(Hr,{children:[t(Tn,{children:"Variant name"}),t(zr,{children:"This will be used to identify the variant in your code"}),t(Lt,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:!!b.name,errorText:b.name,value:l,onChange:y=>V(y.target.value),disabled:$,required:!0})]}),t(T,{condition:P,show:c(Ur,{children:[t(jr,{label:"Custom percentage",control:t(Ra,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:i,onChange:y=>p(y.target.checked)})}),t(qr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:!!b.percentage,errorText:b.percentage,value:u,onChange:y=>B(y.target.value),required:i,disabled:!i,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(Ia,{position:"end",children:"%"})}})]})})]}),c(_t,{children:["Payload",t(at,{tooltip:"Passed along with the the variant object."})]}),c(xn,{children:[t(Yr,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:Jr,onChange:y=>{D("payload"),f(v=>({...v,type:y.target.value}))}}),t(Wr,{children:t(Lt,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:y=>{D("payload"),f(v=>({...v,value:y.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>q(h),error:!!b.payload,errorText:b.payload})})]}),c(_t,{children:["Overrides",t(at,{tooltip:"Here you can specify which users should get this variant."})]}),t(Vr,{overrides:S,overridesDispatch:w}),t("div",{children:t(Kr,{onClick:H,variant:"text",color:"primary","data-testid":"VARIANT_ADD_OVERRIDE_BUTTON",children:"Add override"})})]})};let Fe;const Zr=new Uint8Array(16);function ei(){if(!Fe&&(Fe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Fe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Fe(Zr)}const ti=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Nt={randomUUID:ti};function et(e,n,a){if(Nt.randomUUID&&!n&&!e)return Nt.randomUUID();e=e||{};const o=e.random||(e.rng||ei)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,n){a=a||0;for(let s=0;s<16;++s)n[a+s]=o[s];return n}return Ao(o)}const ni=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})),ai=d(ln,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),oi=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})),si=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ri=d(le)(({theme:e})=>({marginBottom:e.spacing(2)})),ii=d(le)(({theme:e})=>({marginTop:e.spacing(4)})),ci=d("div")({display:"flex",flexDirection:"column"}),li=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),zt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),di=d(we)(({theme:e})=>({margin:e.spacing(4,0)})),ui=d(Da)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),pi=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),gi=d(de)(({theme:e})=>({marginLeft:e.spacing(3)})),hi=({environment:e,open:n,setOpen:a,getApiPayload:o,getCrPayload:s,onConfirm:l})=>{const r=I("projectId"),i=I("featureId"),{uiConfig:p}=Ne(),{context:u}=ht(),{defaultStickiness:g,loading:h}=ka(r),{isChangeRequestConfigured:f}=se(r),{data:S}=ye(r),{changeRequestInReviewOrApproved:w,alert:x}=$a(S),b=(e==null?void 0:e.variants)||[],[C,D]=m.useState([]),[k,$]=m.useState();m.useEffect(()=>{h||D(b.length?b.map(R=>({...R,isValid:!0,new:!1,id:et()})):[{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(C==null?void 0:C.length)>0?C[0].stickiness:g,new:!0,isValid:!1,id:et()}])},[n,h]);const P=(R,G)=>{D(ue=>Ct(ue.map(ke=>ke.id===G?R:ke),1e3))},F=()=>{const R=et();D(G=>[...G,{name:"",weightType:Q.VARIABLE,weight:0,overrides:[],stickiness:(G==null?void 0:G.length)>0?G[0].stickiness:g,new:!0,isValid:!1,id:R}]),$(R)};m.useEffect(()=>{if(k){const R=document.getElementById(`variant-name-input-${k}`);R==null||R.scrollIntoView({behavior:"smooth",block:"center"}),R==null||R.focus({preventScroll:!0}),$(void 0)}},[k]);const V=C.map(({new:R,isValid:G,id:ue,...ke})=>ke),B=o(b,V),q=s(V),H=async R=>{R.preventDefault(),l(V)},Z=()=>y?`curl --location --request POST '${p.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(q,void 0,2)}'`:`curl --location --request PATCH '${p.unleashUrl}/api/admin/projects/${r}/features/${i}/environments/${e==null?void 0:e.name}/variants' \\
|
|
5
5
|
--header 'Authorization: INSERT_API_KEY' \\
|
|
6
6
|
--header 'Content-Type: application/json' \\
|
|
7
|
-
--data-raw '${JSON.stringify(B.patch,void 0,2)}'`,ee=C.every(({isValid:R})=>R),A=w((e==null?void 0:e.name)||""),M=A?"Add to existing change request":"Add change to draft",y=f((e==null?void 0:e.name)||""),v=m.useMemo(()=>{var R;return h?"":((R=V[0])==null?void 0:R.stickiness)||g},[h,g,JSON.stringify(V[0]??{})]),E=m.useMemo(()=>["default",...u.filter(R=>R.stickiness).map(R=>R.name)],[u]),_=E.map(R=>({key:R,label:R}));E.includes(v)||_.push({key:v,label:v});const N=async R=>{D(G=>G.map(ue=>({...ue,stickiness:R})))},L=R=>{N(R)},[W,Ie]=m.useState();m.useEffect(()=>{Ie(void 0),B.error&&Ie(B.error)},[B.error]);const De=()=>{N(g),a(!1)};return h||v===""?t(Fa,{}):t(ot,{open:n,onClose:De,label:"",children:c(Ba,{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:Z,loading:!n,children:[c(ni,{children:[c("div",{children:[t(ai,{deprecated:!(e!=null&&e.enabled)}),t(oi,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ne,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:F,variant:"outlined",permission:pe,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(si,{onSubmit:H,children:[t(T,{condition:A,show:x,elseShow:t(T,{condition:!!y,show:c(ri,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(ci,{children:C.map(R=>t(Qr,{variant:R,variants:C,updateVariant:G=>P(G,R.id),removeVariant:()=>D(G=>Ct(G.filter(ue=>ue.id!==R.id),1e3)),projectId:r,apiPayload:B},R.id))}),t(ne,{onClick:F,variant:"outlined",permission:pe,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(di,{}),t(T,{condition:C.length>0,show:c(O,{children:[t(li,{children:t("p",{children:"Stickiness"})}),c(zt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(gt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(ui,{value:v,label:"",editable:!0,onChange:R=>L(R.target.value)})})]}),elseShow:t(zt,{children:"This environment has no variants. Get started by adding a variant."})}),c(ii,{severity:"error",hidden:!W,children:[t("strong",{children:"Error: "}),W]}),c(pi,{children:[t(de,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ee,children:y?M:"Save variants"}),t(gi,{onClick:De,children:"Cancel"})]})]})]})})},fi=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)}})),mi=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),yi=d(ln,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Si=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})),bi=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ci=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),vi=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),wi=({environment:e,searchValue:n,children:a})=>{var l;const o=e.variants??[],s=((l=o[0])==null?void 0:l.stickiness)||"default";return c(fi,{children:[c(mi,{children:[c("div",{children:[t(yi,{deprecated:!e.enabled}),t(Si,{deprecated:!e.enabled,children:e.name})]}),a]}),t(T,{condition:o.length>0,show:c(O,{children:[t(Ci,{children:t(Pa,{variants:o,searchValue:n})}),t(T,{condition:o.length>1,show:c(O,{children:[c(vi,{children:[t("p",{children:"Stickiness:"}),t(ve,{children:s})]}),c(bi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(gt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},Ti=d(Ce)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),xi=({environment:e,permission:n,projectId:a,environmentId:o,onCopyVariantsFrom:s,otherEnvsWithVariants:l})=>{const[r,i]=m.useState(null),p=!!r,u=e.variants??[];return t(T,{condition:l.length>0&&u.length===0,show:c(O,{children:[t(ne,{onClick:g=>{i(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":p?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":p?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:o,children:"Copy variants from"}),t(Re,{anchorEl:r,open:p,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:l.map(g=>t(fe,{onClick:()=>s(g,e),children:t(Ti,{children:`Copy from ${g.name}`})},g.name))})]})})},Ai=({permission:e,projectId:n,environment:a,checked:o,onClick:s,...l})=>{const r=nt(e,n,a);return c(fe,{disabled:!r,onClick:s,...l,children:[t(Oa,{checked:o}),a]})},Ei=d(Re)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Ri=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),Ii=d(de)(({theme:e})=>({marginTop:e.spacing(2)})),Di=({current:e,environments:n,permission:a,projectId:o,onSubmit:s})=>{var x;const[l,r]=m.useState(null),i=!!l,[p,u]=m.useState([]),g=b=>{u(C=>[...C,b])},h=b=>{u(C=>C.filter(({name:D})=>D!==b.name))},f=b=>{p.includes(b)?h(b):g(b)},S=()=>{u([]),r(null)},w=((x=n.find(b=>b.name===e))==null?void 0:x.variants)??[];return t(T,{condition:w.length>0&&n.length>1,show:c(O,{children:[t(de,{onClick:b=>{r(b.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,variant:"outlined",children:"Push to environment"}),c(Ei,{anchorEl:l,open:i,onClose:()=>r(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(b=>b.name!==e).map(b=>t(Ai,{projectId:o,permission:a,environment:b.name,checked:p.includes(b),onClick:()=>f(b)},b.name)),c(Ri,{children:[t(we,{}),c(Ii,{variant:"outlined",onClick:()=>{s(p),S()},disabled:p.length===0,children:["Push to selected (",p.length,")"]})]})]})]})})},ki=d(le)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),Fi=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Bi=()=>{const{setToastData:e,setToastApiError:n}=K(),a=Jt(),o=_e(a.breakpoints.down("md")),s=I("projectId"),l=I("featureId"),{feature:r,refetchFeature:i,loading:p}=z(s,l),{patchFeatureEnvironmentVariants:u,overrideVariantsInEnvironments:g}=ze(),{refetch:h}=ye(s),{addChange:f}=Me(),{isChangeRequestConfigured:S}=se(s),[w,x]=m.useState(""),[b,C]=m.useState(),[D,k]=m.useState(!1),$=m.useMemo(()=>{var A;return((A=r==null?void 0:r.environments)==null?void 0:A.map(M=>({...M,crEnabled:S(M.name)})))||[]},[r.environments]),P=(A,M)=>_a(A,M),F=(A,M)=>{try{const y=Ma(M,1e3);return{patch:P(A,y)}}catch(y){return{patch:[],error:U(y)}}},V=A=>({feature:l,action:"patchVariant",payload:{variants:A}}),B=async(A,M)=>{if(A.crEnabled)await f(s,A.name,V(M)),h();else{const y=A.variants??[],{patch:v,error:E}=F(y,M);if(v.length===0)return;if(E){e({type:"error",title:E});return}await u(s,l,A.name,v)}i()},q=async(A,M)=>{try{const y=M.filter(({crEnabled:L})=>L),v=M.filter(({crEnabled:L})=>!L);y.length&&await Promise.all(y.map(L=>f(s,L.name,V(A)))),v.length&&await g(s,l,A,v.map(({name:L})=>L)),h(),i();const E=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",_=y.length?`Variants push added to ${y.length===1?`${y[0].name} draft`:`${y.length} drafts`}`:"",N=`${E}${E&&_?". ":""}${_}`;e({title:N,type:"success"})}catch(y){n(U(y))}},H=A=>{C(A),k(!0)},Z=async A=>{if(b)try{await B(b,A),k(!1),e({title:b.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(M){n(U(M))}},ee=async(A,M)=>{try{const y=A.variants??[];await B(M,y),e({title:M.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(y){n(U(y))}};return c(ft,{isLoading:p,header:t(Va,{title:"Variants",actions:t(T,{condition:!o,show:t(O,{children:t(vt,{initialValue:w,onChange:x})})}),children:t(T,{condition:o,show:t(vt,{initialValue:w,onChange:x})})}),children:[c(ki,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(A=>{var y;const M=$.filter(({name:v,variants:E})=>v!==A.name&&(E==null?void 0:E.length));return t(wi,{environment:A,searchValue:w,children:c(Fi,{children:[t(Di,{current:A.name,environments:$,permission:pe,projectId:s,onSubmit:v=>q(A.variants??[],v)}),t(xi,{environment:A,permission:pe,projectId:s,environmentId:A.name,onCopyVariantsFrom:ee,otherEnvsWithVariants:M}),t(T,{condition:!!((y=A.variants)!=null&&y.length),show:t(te,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>H(A),permission:pe,projectId:s,environmentId:A.name,tooltipProps:{title:"Edit variants"},children:t(be,{})}),elseShow:t(ne,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>H(A),variant:"outlined",permission:pe,projectId:s,environmentId:A.name,children:"Add variant"})})]})},A.name)}),t(hi,{environment:b,open:D,setOpen:k,getApiPayload:F,getCrPayload:V,onConfirm:Z})]})},$i=xe("api/admin/client-metrics/features"),An=(e,n)=>{const a=xe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:o,error:s}=ct(a,()=>Pi(a)),l=m.useCallback(()=>{lt($i).catch(console.warn)},[]);return{featureMetrics:o==null?void 0:o.data,loading:!s&&!o,refetchFeatureMetrics:l,error:s}},Pi=e=>fetch(e).then(Ve("Features")).then(n=>n.json()).then(),Oi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Te=48,Vi=({hoursBack:e,setHoursBack:n})=>{const a=o=>{n(Mi(o))};return c("div",{children:[t(Oi,{children:"Period"}),t(La,{name:"feature-metrics-period",id:"feature-metrics-period",options:_i,value:String(e),onChange:a,fullWidth:!0})]})},Mi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Te}},_i=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Te}`,label:`Last ${Te} hours`}],Li=({value:e})=>{const{locationSettings:n}=Zt(),a=e?e instanceof Date?wt(e,n.locale):wt(en(e),n.locale):void 0;return t(dn,{lineClamp:1,children:a})},Ni=({metrics:e,tableSectionId:n})=>{const a=_e(Na.breakpoints.down("md")),o=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:s,getTableBodyProps:l,headerGroups:r,rows:i,prepareRow:p,setHiddenColumns:u}=Ue.useTable({initialState:o,columns:jt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:dn}},Ue.useGlobalFilter,Ue.useSortBy);return za([{condition:a,columns:["appName","environment"]}],u,jt),e.length===0?null:c(ja,{...s(),rowHeight:"standard",id:n,children:[t(Wa,{headerGroups:r}),t(Ua,{...l(),children:i.map(g=>(p(g),t(qa,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Ha,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},jt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ga,{icon:t($o,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Li,{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"}],zi=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((s,l)=>s+l.yes,0),[e]),o=m.useMemo(()=>e.reduce((s,l)=>s+l.no,0),[e]);return t(Cn,{...n,totalYes:a,totalNo:o})},ji=({metrics:e,hoursBack:n})=>{const a=Tt(),o=Tt();return e.length===0?c(Y,{mt:6,children:[t(j,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(j,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):c(m.Suspense,{fallback:null,children:[t(Y,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Wi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Y,{mt:4,children:t(zi,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:o})}),t(Y,{mt:4,children:t(Ni,{metrics:e,tableSectionId:o})})]})},Wi=Ya.lazy(()=>import("./FeatureMetricsChart-e1a34382.js")),it=e=>{const{search:n}=window.location,a=ce(),o=m.useMemo(()=>new URLSearchParams(n),[n]),s=m.useCallback(l=>{const r=new URLSearchParams(n);r.set(e,l),a({search:r.toString()},{replace:!0})},[e,n,a]);return[o.get(e)||void 0,s]},Ui=e=>{const[n,a]=it(e),o=m.useCallback(s=>a(String(s)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,o]},qi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Hi=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Gi=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}})),Wt=({title:e,values:n,value:a,setValue:o})=>{const s=r=>()=>{n.has(r)&&o(r)},l=m.useMemo(()=>Array.from(n).sort((r,i)=>r.localeCompare(i)),[n]);return c("div",{children:[t(qi,{children:e}),t(Hi,{children:l.map(r=>t(Gi,{children:t(tn,{label:r,onClick:s(r),"aria-pressed":r===a,sx:Ka})},r))})]})},Yi=()=>{const e=I("projectId"),n=I("featureId"),a=Ki(e,n),o=Ji(n);nn("Metrics");const[s=Te,l]=Ui("hoursBack"),{featureMetrics:r}=An(n,s),[i,p]=m.useState(r);m.useEffect(()=>{r&&p(r)},[r]);const u=Array.from(a)[0],g=Array.from(o)[0],[h=u,f]=it("environment"),[S=g,w]=it("application"),x=m.useMemo(()=>i==null?void 0:i.filter(b=>b.environment===h).filter(b=>b.appName===S),[i,h,S]);return x?c(ft,{children:[c(ae,{container:!0,component:"header",spacing:2,children:[t(ae,{item:!0,xs:12,md:5,children:t(T,{condition:a.size>0,show:t(Wt,{title:"Environments",values:a,value:h,setValue:f})})}),t(ae,{item:!0,xs:12,md:5,children:t(T,{condition:o.size>0,show:t(Wt,{title:"Applications",values:o,value:S,setValue:w})})}),t(ae,{item:!0,xs:12,md:2,children:t(Vi,{hoursBack:s,setHoursBack:l})})]}),t(ji,{metrics:x,hoursBack:s})]}):null},Ki=(e,n)=>{const{feature:a}=z(e,n),o=a.environments.map(s=>s.name);return new Set(o)},Ji=e=>{const{featureMetrics:n=[]}=An(e,Te),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))},Ut=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),qt=d(le)(({theme:e})=>({marginBottom:e.spacing(1)})),Qi=d(pt)({padding:0}),Zi=({projectId:e,open:n,onClose:a,onClick:o,feature:s,changeRequests:l})=>{const r=I("projectId"),{project:i}=un(e),{isChangeRequestConfiguredInAnyEnv:p}=se(e),u=p(),g=m.useMemo(()=>Xi(s.environments.map(f=>f.name),i.environments.map(f=>f.environment)),[s,i]),h=l?l.length>0:!1;return t(T,{condition:g&&!h&&!u,show:t(ie,{open:n,onClose:a,onClick:o,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(Ut,{children:[t(qt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ie,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:c(Ut,{children:[t(qt,{severity:"warning",children:"Cannot proceed with the move"}),t(T,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(T,{condition:h,show:c(O,{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(Qi,{children:l==null?void 0:l.map(f=>t(ge,{children:c(X,{to:`/projects/${r}/change-requests/${f.id}`,children:["View change request"," ",f.id]})},f.id))})]})}),t(T,{condition:u,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(X,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},ec=e=>fetch(e).then(Ve("ChangeRequest")).then(n=>n.json()),tc=(e,n)=>{const{data:a,error:o,mutate:s}=Ja([],xe(`api/admin/projects/${e}/change-requests/pending/${n}`),ec);return{changeRequests:a,loading:!o&&!a,refetch:s,error:o}},nc=()=>{const{hasAccess:e}=m.useContext(dt),n=I("projectId"),a=I("featureId"),{feature:o,refetchFeature:s}=z(n,a),[l,r]=m.useState(!1),{changeFeatureProject:i}=ze(),{setToastData:p,setToastApiError:u}=K(),[g,h]=m.useState(n),{projects:f}=Xa(),S=ce(),{changeRequests:w}=tc(n,a),x=async()=>{try{g&&(await i(n,a,g),s(),p({title:"Project changed",type:"success"}),r(!1),S(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(C){u(U(C))}},b=m.useMemo(()=>f.map(C=>C.id).filter(C=>e(xt,C)),[f,e]);return b.length===0?null:c(O,{children:[t(Qa,{value:g,onChange:h,label:"Project",filter:C=>b.includes(C),enabled:!0}),t(ne,{permission:xt,onClick:()=>r(!0),disabled:g===n,projectId:n,children:"Save"}),t(Zi,{changeRequests:w,projectId:g,open:l,feature:o,onClose:()=>r(!1),onClick:x})]})},ac=d("div")({display:"flex",alignItems:"center"}),oc=d(j)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),sc=({projectId:e,featureId:n})=>{var l;const{feature:a}=z(e,n),o=ce();return c(O,{children:[c(ac,{children:[t(oc,{children:"Feature information"}),t(te,{permission:he,projectId:e,"data-loading":!0,onClick:()=>{o(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(be,{})})]}),c(j,{children:["Name: ",t("strong",{children:a.name})]}),c(j,{children:["Description:"," ",t("strong",{children:(l=a.description)!=null&&l.length?a.description:"no description"})]}),c(j,{children:["Type: ",t("strong",{children:a.type})]}),c(j,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Be="metadata",tt="project",rc=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ic=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),cc=()=>{const e=I("projectId"),n=I("featureId"),[a,o]=m.useState(Be),{uiConfig:s}=Ne();return t(ft,{header:"Settings",sx:{padding:0},children:c(Y,{sx:{display:"flex"},children:[t(rc,{children:c(pt,{children:[t(ge,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(Be),selected:a===Be,children:"Metadata"},0),t(ge,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(tt),selected:a===tt,hidden:!s.flags.P,children:"Project"},1)]})}),c(ic,{children:[t(T,{condition:a===Be,show:t(sc,{projectId:e,featureId:n})}),t(T,{condition:a===tt&&s.flags.P,show:t(nc,{})})]})]})})},lc=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(ve,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),Ht=d("strong")({wordBreak:"break-all"}),dc=()=>{const e=I("projectId"),n=I("featureId"),{archivedFeatures:a}=Za(),o=eo(e,{name:n});return a?a.some(l=>l.name===n)?c("p",{children:["The feature ",t(Ht,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(Ht,{children:n})," does not exist. Would you like to"," ",t(X,{to:o,children:"create it"}),"?"]}):null},uc=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),pc=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),gc=d("div")({display:"flex",alignItems:"center"}),hc=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),fc=d("div")({flexShrink:0,display:"flex"}),mc=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),yc=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Sc=d(to)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Tc=()=>{const e=I("projectId"),n=I("featureId"),{refetch:a}=un(e),{favorite:o,unfavorite:s}=no(),{refetchFeature:l}=z(e,n),[r,i]=m.useState(!1),[p,u]=m.useState(!1),[g,h]=m.useState(!1),f=_e("(max-width:500px)"),{feature:S,loading:w,error:x,status:b}=z(e,n),C=ce(),{pathname:D}=ao(),k=oo(w),$=`/projects/${e}/features/${n}`,P=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],F=P.find(B=>B.path===D)??P[0],V=async()=>{S!=null&&S.favorite?await s(e,S.name):await o(e,S.name),l()};return b===404?t(dc,{}):x!==void 0?t("div",{ref:k}):c("div",{ref:k,children:[c(uc,{children:[c(pc,{children:[c(gc,{children:[t(so,{onClick:V,isFavorite:S==null?void 0:S.favorite}),c(hc,{"data-loading":!0,children:[S.name," "]}),t(T,{condition:!f,show:t(lc,{stale:S==null?void 0:S.stale})})]}),c(fc,{children:[t(te,{permission:ro,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(io,{})}),t(te,{permission:co,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(Bo,{})}),t(te,{onClick:()=>h(!0),permission:he,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(vo,{})}),t(te,{onClick:()=>i(!0),permission:he,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(lo,{})})]})]}),t(mc,{}),t(yc,{children:t(uo,{value:F.path,indicatorColor:"primary",textColor:"primary",children:P.map(B=>t(Sc,{label:B.title,value:B.path,onClick:()=>C(B.path),"data-testid":`TAB-${B.title}`},B.title))})})]}),c(an,{children:[t(re,{path:"metrics",element:t(Yi,{})}),t(re,{path:"logs",element:t(Oo,{})}),t(re,{path:"variants",element:t(Bi,{})}),t(re,{path:"settings",element:t(cc,{})}),t(re,{path:"*",element:t(Dr,{})})]}),t(wo,{isOpen:p,onConfirm:()=>{a(),C(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureIds:[n]}),t(To,{isStale:S.stale,isOpen:g,onClose:()=>{h(!1),l()},featureId:n,projectId:e}),t(wn,{open:r,setOpen:i})]})};export{Tc as default};
|
|
7
|
+
--data-raw '${JSON.stringify(B.patch,void 0,2)}'`,ee=C.every(({isValid:R})=>R),A=w((e==null?void 0:e.name)||""),M=A?"Add to existing change request":"Add change to draft",y=f((e==null?void 0:e.name)||""),v=m.useMemo(()=>{var R;return h?"":((R=V[0])==null?void 0:R.stickiness)||g},[h,g,JSON.stringify(V[0]??{})]),E=m.useMemo(()=>["default",...u.filter(R=>R.stickiness).map(R=>R.name)],[u]),_=E.map(R=>({key:R,label:R}));E.includes(v)||_.push({key:v,label:v});const N=async R=>{D(G=>G.map(ue=>({...ue,stickiness:R})))},L=R=>{N(R)},[W,Ie]=m.useState();m.useEffect(()=>{Ie(void 0),B.error&&Ie(B.error)},[B.error]);const De=()=>{N(g),a(!1)};return h||v===""?t(Fa,{}):t(ot,{open:n,onClose:De,label:"",children:c(Ba,{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:Z,loading:!n,children:[c(ni,{children:[c("div",{children:[t(ai,{deprecated:!(e!=null&&e.enabled)}),t(oi,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ne,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:F,variant:"outlined",permission:pe,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(si,{onSubmit:H,children:[t(T,{condition:A,show:x,elseShow:t(T,{condition:!!y,show:c(ri,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(ci,{children:C.map(R=>t(Qr,{variant:R,variants:C,updateVariant:G=>P(G,R.id),removeVariant:()=>D(G=>Ct(G.filter(ue=>ue.id!==R.id),1e3)),projectId:r,apiPayload:B},R.id))}),t(ne,{onClick:F,variant:"outlined",permission:pe,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(di,{}),t(T,{condition:C.length>0,show:c(O,{children:[t(li,{children:t("p",{children:"Stickiness"})}),c(zt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(gt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(ui,{value:v,label:"",editable:!0,onChange:R=>L(R.target.value)})})]}),elseShow:t(zt,{children:"This environment has no variants. Get started by adding a variant."})}),c(ii,{severity:"error",hidden:!W,children:[t("strong",{children:"Error: "}),W]}),c(pi,{children:[t(de,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!ee,children:y?M:"Save variants"}),t(gi,{onClick:De,children:"Cancel"})]})]})]})})},fi=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)}})),mi=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),yi=d(ln,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Si=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})),bi=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ci=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),vi=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),wi=({environment:e,searchValue:n,children:a})=>{var l;const o=e.variants??[],s=((l=o[0])==null?void 0:l.stickiness)||"default";return c(fi,{children:[c(mi,{children:[c("div",{children:[t(yi,{deprecated:!e.enabled}),t(Si,{deprecated:!e.enabled,children:e.name})]}),a]}),t(T,{condition:o.length>0,show:c(O,{children:[t(Ci,{children:t(Pa,{variants:o,searchValue:n})}),t(T,{condition:o.length>1,show:c(O,{children:[c(vi,{children:[t("p",{children:"Stickiness:"}),t(ve,{children:s})]}),c(bi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(gt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},Ti=d(Ce)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),xi=({environment:e,permission:n,projectId:a,environmentId:o,onCopyVariantsFrom:s,otherEnvsWithVariants:l})=>{const[r,i]=m.useState(null),p=!!r,u=e.variants??[];return t(T,{condition:l.length>0&&u.length===0,show:c(O,{children:[t(ne,{onClick:g=>{i(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":p?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":p?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:o,children:"Copy variants from"}),t(Re,{anchorEl:r,open:p,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:l.map(g=>t(fe,{onClick:()=>s(g,e),children:t(Ti,{children:`Copy from ${g.name}`})},g.name))})]})})},Ai=({permission:e,projectId:n,environment:a,checked:o,onClick:s,...l})=>{const r=nt(e,n,a);return c(fe,{disabled:!r,onClick:s,...l,children:[t(Oa,{checked:o}),a]})},Ei=d(Re)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Ri=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),Ii=d(de)(({theme:e})=>({marginTop:e.spacing(2)})),Di=({current:e,environments:n,permission:a,projectId:o,onSubmit:s})=>{var x;const[l,r]=m.useState(null),i=!!l,[p,u]=m.useState([]),g=b=>{u(C=>[...C,b])},h=b=>{u(C=>C.filter(({name:D})=>D!==b.name))},f=b=>{p.includes(b)?h(b):g(b)},S=()=>{u([]),r(null)},w=((x=n.find(b=>b.name===e))==null?void 0:x.variants)??[];return t(T,{condition:w.length>0&&n.length>1,show:c(O,{children:[t(de,{onClick:b=>{r(b.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,variant:"outlined",children:"Push to environment"}),c(Ei,{anchorEl:l,open:i,onClose:()=>r(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(b=>b.name!==e).map(b=>t(Ai,{projectId:o,permission:a,environment:b.name,checked:p.includes(b),onClick:()=>f(b)},b.name)),c(Ri,{children:[t(we,{}),c(Ii,{variant:"outlined",onClick:()=>{s(p),S()},disabled:p.length===0,children:["Push to selected (",p.length,")"]})]})]})]})})},ki=d(le)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),Fi=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),Bi=()=>{const{setToastData:e,setToastApiError:n}=K(),a=Jt(),o=_e(a.breakpoints.down("md")),s=I("projectId"),l=I("featureId"),{feature:r,refetchFeature:i,loading:p}=z(s,l),{patchFeatureEnvironmentVariants:u,overrideVariantsInEnvironments:g}=ze(),{refetch:h}=ye(s),{addChange:f}=Me(),{isChangeRequestConfigured:S}=se(s),[w,x]=m.useState(""),[b,C]=m.useState(),[D,k]=m.useState(!1),$=m.useMemo(()=>{var A;return((A=r==null?void 0:r.environments)==null?void 0:A.map(M=>({...M,crEnabled:S(M.name)})))||[]},[r.environments]),P=(A,M)=>_a(A,M),F=(A,M)=>{try{const y=Ma(M,1e3);return{patch:P(A,y)}}catch(y){return{patch:[],error:U(y)}}},V=A=>({feature:l,action:"patchVariant",payload:{variants:A}}),B=async(A,M)=>{if(A.crEnabled)await f(s,A.name,V(M)),h();else{const y=A.variants??[],{patch:v,error:E}=F(y,M);if(v.length===0)return;if(E){e({type:"error",title:E});return}await u(s,l,A.name,v)}i()},q=async(A,M)=>{try{const y=M.filter(({crEnabled:L})=>L),v=M.filter(({crEnabled:L})=>!L);y.length&&await Promise.all(y.map(L=>f(s,L.name,V(A)))),v.length&&await g(s,l,A,v.map(({name:L})=>L)),h(),i();const E=v.length?`Variants pushed to ${v.length===1?v[0].name:`${v.length} environments`}`:"",_=y.length?`Variants push added to ${y.length===1?`${y[0].name} draft`:`${y.length} drafts`}`:"",N=`${E}${E&&_?". ":""}${_}`;e({title:N,type:"success"})}catch(y){n(U(y))}},H=A=>{C(A),k(!0)},Z=async A=>{if(b)try{await B(b,A),k(!1),e({title:b.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(M){n(U(M))}},ee=async(A,M)=>{try{const y=A.variants??[];await B(M,y),e({title:M.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(y){n(U(y))}};return c(ft,{isLoading:p,header:t(Va,{title:"Variants",actions:t(T,{condition:!o,show:t(O,{children:t(vt,{initialValue:w,onChange:x})})}),children:t(T,{condition:o,show:t(vt,{initialValue:w,onChange:x})})}),children:[c(ki,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(A=>{var y;const M=$.filter(({name:v,variants:E})=>v!==A.name&&(E==null?void 0:E.length));return t(wi,{environment:A,searchValue:w,children:c(Fi,{children:[t(Di,{current:A.name,environments:$,permission:pe,projectId:s,onSubmit:v=>q(A.variants??[],v)}),t(xi,{environment:A,permission:pe,projectId:s,environmentId:A.name,onCopyVariantsFrom:ee,otherEnvsWithVariants:M}),t(T,{condition:!!((y=A.variants)!=null&&y.length),show:t(te,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>H(A),permission:pe,projectId:s,environmentId:A.name,tooltipProps:{title:"Edit variants"},children:t(be,{})}),elseShow:t(ne,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>H(A),variant:"outlined",permission:pe,projectId:s,environmentId:A.name,children:"Add variant"})})]})},A.name)}),t(hi,{environment:b,open:D,setOpen:k,getApiPayload:F,getCrPayload:V,onConfirm:Z})]})},$i=xe("api/admin/client-metrics/features"),An=(e,n)=>{const a=xe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:o,error:s}=ct(a,()=>Pi(a)),l=m.useCallback(()=>{lt($i).catch(console.warn)},[]);return{featureMetrics:o==null?void 0:o.data,loading:!s&&!o,refetchFeatureMetrics:l,error:s}},Pi=e=>fetch(e).then(Ve("Features")).then(n=>n.json()).then(),Oi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Te=48,Vi=({hoursBack:e,setHoursBack:n})=>{const a=o=>{n(Mi(o))};return c("div",{children:[t(Oi,{children:"Period"}),t(La,{name:"feature-metrics-period",id:"feature-metrics-period",options:_i,value:String(e),onChange:a,fullWidth:!0})]})},Mi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Te}},_i=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Te}`,label:`Last ${Te} hours`}],Li=({value:e})=>{const{locationSettings:n}=Zt(),a=e?e instanceof Date?wt(e,n.locale):wt(en(e),n.locale):void 0;return t(dn,{lineClamp:1,children:a})},Ni=({metrics:e,tableSectionId:n})=>{const a=_e(Na.breakpoints.down("md")),o=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:s,getTableBodyProps:l,headerGroups:r,rows:i,prepareRow:p,setHiddenColumns:u}=Ue.useTable({initialState:o,columns:jt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:dn}},Ue.useGlobalFilter,Ue.useSortBy);return za([{condition:a,columns:["appName","environment"]}],u,jt),e.length===0?null:c(ja,{...s(),rowHeight:"standard",id:n,children:[t(Wa,{headerGroups:r}),t(Ua,{...l(),children:i.map(g=>(p(g),t(qa,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t(Ha,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},jt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ga,{icon:t($o,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Li,{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"}],zi=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((s,l)=>s+l.yes,0),[e]),o=m.useMemo(()=>e.reduce((s,l)=>s+l.no,0),[e]);return t(Cn,{...n,totalYes:a,totalNo:o})},ji=({metrics:e,hoursBack:n})=>{const a=Tt(),o=Tt();return e.length===0?c(Y,{mt:6,children:[t(j,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(j,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):c(m.Suspense,{fallback:null,children:[t(Y,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Wi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Y,{mt:4,children:t(zi,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:o})}),t(Y,{mt:4,children:t(Ni,{metrics:e,tableSectionId:o})})]})},Wi=Ya.lazy(()=>import("./FeatureMetricsChart-70a6747e.js")),it=e=>{const{search:n}=window.location,a=ce(),o=m.useMemo(()=>new URLSearchParams(n),[n]),s=m.useCallback(l=>{const r=new URLSearchParams(n);r.set(e,l),a({search:r.toString()},{replace:!0})},[e,n,a]);return[o.get(e)||void 0,s]},Ui=e=>{const[n,a]=it(e),o=m.useCallback(s=>a(String(s)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,o]},qi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Hi=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Gi=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}})),Wt=({title:e,values:n,value:a,setValue:o})=>{const s=r=>()=>{n.has(r)&&o(r)},l=m.useMemo(()=>Array.from(n).sort((r,i)=>r.localeCompare(i)),[n]);return c("div",{children:[t(qi,{children:e}),t(Hi,{children:l.map(r=>t(Gi,{children:t(tn,{label:r,onClick:s(r),"aria-pressed":r===a,sx:Ka})},r))})]})},Yi=()=>{const e=I("projectId"),n=I("featureId"),a=Ki(e,n),o=Ji(n);nn("Metrics");const[s=Te,l]=Ui("hoursBack"),{featureMetrics:r}=An(n,s),[i,p]=m.useState(r);m.useEffect(()=>{r&&p(r)},[r]);const u=Array.from(a)[0],g=Array.from(o)[0],[h=u,f]=it("environment"),[S=g,w]=it("application"),x=m.useMemo(()=>i==null?void 0:i.filter(b=>b.environment===h).filter(b=>b.appName===S),[i,h,S]);return x?c(ft,{children:[c(ae,{container:!0,component:"header",spacing:2,children:[t(ae,{item:!0,xs:12,md:5,children:t(T,{condition:a.size>0,show:t(Wt,{title:"Environments",values:a,value:h,setValue:f})})}),t(ae,{item:!0,xs:12,md:5,children:t(T,{condition:o.size>0,show:t(Wt,{title:"Applications",values:o,value:S,setValue:w})})}),t(ae,{item:!0,xs:12,md:2,children:t(Vi,{hoursBack:s,setHoursBack:l})})]}),t(ji,{metrics:x,hoursBack:s})]}):null},Ki=(e,n)=>{const{feature:a}=z(e,n),o=a.environments.map(s=>s.name);return new Set(o)},Ji=e=>{const{featureMetrics:n=[]}=An(e,Te),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))},Ut=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),qt=d(le)(({theme:e})=>({marginBottom:e.spacing(1)})),Qi=d(pt)({padding:0}),Zi=({projectId:e,open:n,onClose:a,onClick:o,feature:s,changeRequests:l})=>{const r=I("projectId"),{project:i}=un(e),{isChangeRequestConfiguredInAnyEnv:p}=se(e),u=p(),g=m.useMemo(()=>Xi(s.environments.map(f=>f.name),i.environments.map(f=>f.environment)),[s,i]),h=l?l.length>0:!1;return t(T,{condition:g&&!h&&!u,show:t(ie,{open:n,onClose:a,onClick:o,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(Ut,{children:[t(qt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ie,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:c(Ut,{children:[t(qt,{severity:"warning",children:"Cannot proceed with the move"}),t(T,{condition:!g,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(T,{condition:h,show:c(O,{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(Qi,{children:l==null?void 0:l.map(f=>t(ge,{children:c(X,{to:`/projects/${r}/change-requests/${f.id}`,children:["View change request"," ",f.id]})},f.id))})]})}),t(T,{condition:u,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(X,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},ec=e=>fetch(e).then(Ve("ChangeRequest")).then(n=>n.json()),tc=(e,n)=>{const{data:a,error:o,mutate:s}=Ja([],xe(`api/admin/projects/${e}/change-requests/pending/${n}`),ec);return{changeRequests:a,loading:!o&&!a,refetch:s,error:o}},nc=()=>{const{hasAccess:e}=m.useContext(dt),n=I("projectId"),a=I("featureId"),{feature:o,refetchFeature:s}=z(n,a),[l,r]=m.useState(!1),{changeFeatureProject:i}=ze(),{setToastData:p,setToastApiError:u}=K(),[g,h]=m.useState(n),{projects:f}=Xa(),S=ce(),{changeRequests:w}=tc(n,a),x=async()=>{try{g&&(await i(n,a,g),s(),p({title:"Project changed",type:"success"}),r(!1),S(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(C){u(U(C))}},b=m.useMemo(()=>f.map(C=>C.id).filter(C=>e(xt,C)),[f,e]);return b.length===0?null:c(O,{children:[t(Qa,{value:g,onChange:h,label:"Project",filter:C=>b.includes(C),enabled:!0}),t(ne,{permission:xt,onClick:()=>r(!0),disabled:g===n,projectId:n,children:"Save"}),t(Zi,{changeRequests:w,projectId:g,open:l,feature:o,onClose:()=>r(!1),onClick:x})]})},ac=d("div")({display:"flex",alignItems:"center"}),oc=d(j)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),sc=({projectId:e,featureId:n})=>{var l;const{feature:a}=z(e,n),o=ce();return c(O,{children:[c(ac,{children:[t(oc,{children:"Feature information"}),t(te,{permission:he,projectId:e,"data-loading":!0,onClick:()=>{o(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(be,{})})]}),c(j,{children:["Name: ",t("strong",{children:a.name})]}),c(j,{children:["Description:"," ",t("strong",{children:(l=a.description)!=null&&l.length?a.description:"no description"})]}),c(j,{children:["Type: ",t("strong",{children:a.type})]}),c(j,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Be="metadata",tt="project",rc=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),ic=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),cc=()=>{const e=I("projectId"),n=I("featureId"),[a,o]=m.useState(Be),{uiConfig:s}=Ne();return t(ft,{header:"Settings",sx:{padding:0},children:c(Y,{sx:{display:"flex"},children:[t(rc,{children:c(pt,{children:[t(ge,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(Be),selected:a===Be,children:"Metadata"},0),t(ge,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(tt),selected:a===tt,hidden:!s.flags.P,children:"Project"},1)]})}),c(ic,{children:[t(T,{condition:a===Be,show:t(sc,{projectId:e,featureId:n})}),t(T,{condition:a===tt&&s.flags.P,show:t(nc,{})})]})]})})},lc=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(ve,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),Ht=d("strong")({wordBreak:"break-all"}),dc=()=>{const e=I("projectId"),n=I("featureId"),{archivedFeatures:a}=Za(),o=eo(e,{name:n});return a?a.some(l=>l.name===n)?c("p",{children:["The feature ",t(Ht,{children:n})," has been archived. You can find it on the"," ",t(X,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(Ht,{children:n})," does not exist. Would you like to"," ",t(X,{to:o,children:"create it"}),"?"]}):null},uc=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),pc=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),gc=d("div")({display:"flex",alignItems:"center"}),hc=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),fc=d("div")({flexShrink:0,display:"flex"}),mc=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),yc=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Sc=d(to)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Tc=()=>{const e=I("projectId"),n=I("featureId"),{refetch:a}=un(e),{favorite:o,unfavorite:s}=no(),{refetchFeature:l}=z(e,n),[r,i]=m.useState(!1),[p,u]=m.useState(!1),[g,h]=m.useState(!1),f=_e("(max-width:500px)"),{feature:S,loading:w,error:x,status:b}=z(e,n),C=ce(),{pathname:D}=ao(),k=oo(w),$=`/projects/${e}/features/${n}`,P=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],F=P.find(B=>B.path===D)??P[0],V=async()=>{S!=null&&S.favorite?await s(e,S.name):await o(e,S.name),l()};return b===404?t(dc,{}):x!==void 0?t("div",{ref:k}):c("div",{ref:k,children:[c(uc,{children:[c(pc,{children:[c(gc,{children:[t(so,{onClick:V,isFavorite:S==null?void 0:S.favorite}),c(hc,{"data-loading":!0,children:[S.name," "]}),t(T,{condition:!f,show:t(lc,{stale:S==null?void 0:S.stale})})]}),c(fc,{children:[t(te,{permission:ro,projectId:e,"data-loading":!0,component:X,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(io,{})}),t(te,{permission:co,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(Bo,{})}),t(te,{onClick:()=>h(!0),permission:he,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(vo,{})}),t(te,{onClick:()=>i(!0),permission:he,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(lo,{})})]})]}),t(mc,{}),t(yc,{children:t(uo,{value:F.path,indicatorColor:"primary",textColor:"primary",children:P.map(B=>t(Sc,{label:B.title,value:B.path,onClick:()=>C(B.path),"data-testid":`TAB-${B.title}`},B.title))})})]}),c(an,{children:[t(re,{path:"metrics",element:t(Yi,{})}),t(re,{path:"logs",element:t(Oo,{})}),t(re,{path:"variants",element:t(Bi,{})}),t(re,{path:"settings",element:t(cc,{})}),t(re,{path:"*",element:t(Dr,{})})]}),t(wo,{isOpen:p,onConfirm:()=>{a(),C(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureIds:[n]}),t(To,{isStale:S.stale,isOpen:g,onClose:()=>{h(!1),l()},featureId:n,projectId:e}),t(wn,{open:r,setOpen:i})]})};export{Tc as default};
|