unleash-server 4.22.0 → 4.22.2
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/dist/lib/routes/admin-api/api-token.js +1 -1
- package/dist/lib/routes/admin-api/api-token.js.map +1 -1
- package/dist/lib/routes/admin-api/project/api-token.js +1 -1
- package/dist/lib/routes/admin-api/project/api-token.js.map +1 -1
- package/dist/lib/routes/admin-api/user/pat.d.ts +1 -0
- package/dist/lib/routes/admin-api/user/pat.js +9 -0
- package/dist/lib/routes/admin-api/user/pat.js.map +1 -1
- package/dist/lib/services/project-schema.js +1 -4
- package/dist/lib/services/project-schema.js.map +1 -1
- package/dist/lib/services/proxy-service.d.ts +6 -1
- package/dist/lib/services/proxy-service.js +18 -7
- package/dist/lib/services/proxy-service.js.map +1 -1
- package/dist/lib/types/experimental.d.ts +1 -0
- package/dist/lib/types/experimental.js +1 -0
- package/dist/lib/types/experimental.js.map +1 -1
- package/dist/test/e2e/api/proxy/proxy.concurrency.e2e.test.d.ts +1 -0
- package/dist/test/e2e/api/proxy/proxy.concurrency.e2e.test.js +58 -0
- package/dist/test/e2e/api/proxy/proxy.concurrency.e2e.test.js.map +1 -0
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{CreateProject-79087949.js → CreateProject-51932050.js} +1 -1
- package/frontend/build/static/{Error-b8ec37c0.js → Error-e6e1194a.js} +1 -1
- package/frontend/build/static/{ExpandMore-4c20b51c.js → ExpandMore-d71bbced.js} +1 -1
- package/frontend/build/static/{FeatureArchiveDialog-b81c4e16.js → FeatureArchiveDialog-fd71aac2.js} +1 -1
- package/frontend/build/static/{FeatureMetricsChart-37e55387.js → FeatureMetricsChart-66e2ebdf.js} +1 -1
- package/frontend/build/static/FeatureViewLazyExport-3403c2b4.js +7 -0
- package/frontend/build/static/{LazyAdminExport-0f2734aa.js → LazyAdminExport-17ef1739.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-cb47b897.js → LazyProjectExport-96365c31.js} +1 -1
- package/frontend/build/static/{NetworkOverview-8b64cc40.js → NetworkOverview-02d7cec9.js} +1 -1
- package/frontend/build/static/{NetworkTraffic-38cef6f4.js → NetworkTraffic-ea8ea762.js} +1 -1
- package/frontend/build/static/{Playground-4e2c6704.js → Playground-1b14c01c.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-d93244f3.js → StrategyItemContainer-7ce39bda.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-24250637.js → chartjs-adapter-date-fns.esm-8ccfeb24.js} +1 -1
- package/frontend/build/static/{index-32a0dc63.js → index-17782336.js} +1 -1
- package/frontend/build/static/{index-c4e310cb.js → index-1d165488.js} +66 -66
- package/frontend/build/static/{index-fe84ab30.js → index-96dcc77e.js} +1 -1
- package/frontend/build/static/{unknownify-8af014d5.js → unknownify-132fbce3.js} +1 -1
- package/frontend/build/static/{useProjectRole-08992a4c.js → useProjectRole-f048973d.js} +1 -1
- package/package.json +1 -1
- package/frontend/build/static/FeatureViewLazyExport-10ea877c.js +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cO as n,cQ as s,cP as o}from"./index-
|
|
1
|
+
import{cO as n,cQ as s,cP as o}from"./index-1d165488.js";function i(e,r){n(2,arguments);var a=s(e),t=o(r);return isNaN(t)?new Date(NaN):(t&&a.setDate(a.getDate()+t),a)}export{i as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{aR as r,aS as a,r as o,aT as c}from"./index-
|
|
1
|
+
import{aR as r,aS as a,r as o,aT as c}from"./index-1d165488.js";const u=(e={})=>{const{data:t,error:n,mutate:s}=r(a("api/admin/metrics/rps"),i,e);return o.useMemo(()=>({metrics:t,loading:!n&&!t,refetch:()=>s(),error:n}),[t,n,s])},i=e=>fetch(e).then(c("Instance Metrics")).then(t=>t.json()),f=e=>!e||e==="undefined"?"unknown":e;export{f as a,u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dX as $,c as L,j as e,H as E,f as l,A as N,N as z,c5 as V,U as X,F as k,C,a as T,X as Y,d8 as q,S as J,h as Q,i as Z,k as ee,W as P,bE as U,ar as te,ds as ne,bJ as oe,dY as se,s as y,aO as F,dH as re,l as B,dJ as A,r as u,I as ae,R as v,c6 as le,dn as ie,d as I,e as ce,a2 as M,aM as H,cl as de,dZ as ue,aY as he,a_ as O,a4 as pe,bS as me,c4 as ye,a9 as be,aj as W,T as w,dD as fe,cX as ge,a5 as Ce,dG as Te,bR as ke,dF as Se,d_ as Ae,aR as ve,aS as G,aT as K,cb as Ie,aU as we}from"./index-c4e310cb.js";const Ee=$(),Ye=Ee,Ne=L(e("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),qe=L(e("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"}),"MoreVert"),De=()=>{const{uiConfig:t}=E();return l(N,{severity:"info",children:[l("p",{children:["Read the"," ",e("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",e("strong",{children:"1 minute"})," before a new API key is activated."]}),e("br",{}),e("strong",{children:"API URL: "})," ",l("pre",{style:{display:"inline"},children:[t.unleashUrl,"/api/"]})]})},xe=["Icon","createdAt"],Re=["Icon","project","seenAt"],Je=({compact:t=!1,setHiddenColumns:n,columns:s,loading:o,rows:r,getTableProps:a,getTableBodyProps:i,headerGroups:c,globalFilter:d,prepareRow:b})=>{const g=z(V.breakpoints.down("md"));return X([{condition:g,columns:xe},{condition:t,columns:Re}],n,s),l(k,{children:[e(C,{condition:r.length>0,show:e(T,{sx:{mb:4},children:e(De,{})})}),e(T,{sx:{overflowX:"auto"},children:e(Y,{value:d,children:l(q,{...a(),children:[e(J,{headerGroups:c}),e(Q,{...i(),children:r.map(f=>(b(f),e(Z,{hover:!0,...f.getRowProps(),children:f.cells.map(h=>e(ee,{...h.getCellProps(),children:h.render("Cell")}))})))})]})})}),e(C,{condition:r.length===0&&!o,show:e(C,{condition:(d==null?void 0:d.length)>0,show:l(P,{children:["No tokens found matching “",d,"”"]}),elseShow:e(P,{children:l("span",{children:["No tokens available. Read ",e(U,{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},Qe=({path:t,permission:n,project:s})=>{const o=te();return e(ne,{Icon:oe,onClick:()=>o(t),"data-testid":se,permission:n,projectId:s,maxWidth:"700px",children:"New API token"})},Pe=y(F)(({theme:t})=>({textDecoration:"none",color:t.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),Be=({projects:t,project:n})=>{const{searchQuery:s}=re();let o=t&&Array.isArray(t)?t:n?[n]:[];return o.length===0?e(B,{children:e(A,{search:s,children:"*"})}):e(B,{children:o.map((r,a)=>l(u.Fragment,{children:[a>0&&", ",!r||r==="*"?e(A,{search:s,children:"*"}):e(Pe,{to:`/projects/${r}`,children:e(A,{search:s,children:r})})]},r))})},Ze=(t,n)=>{const s=u.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]),o=u.useMemo(()=>[{id:"Icon",width:"1%",Cell:()=>e(ae,{icon:e(Ne,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:v},{Header:"Type",accessor:"type",Cell:({value:h})=>e(v,{value:j[h.toLowerCase()].label,subtitle:j[h.toLowerCase()].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:h=>e(Be,{project:h.row.original.project,projects:h.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:v,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:le,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ie,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:n}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:b,setGlobalFilter:g,setHiddenColumns:f}=I.useTable({columns:o,data:t,initialState:s,sortTypes:ce,autoResetHiddenColumns:!1,disableSortRemove:!0},I.useGlobalFilter,I.useSortBy);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:b,setGlobalFilter:g,setHiddenColumns:f,columns:o}},j={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},et=({token:t,project:n,permission:s,track:o})=>{const{setToastData:r}=M(),a=i=>{ue(i)&&(r({type:"success",title:"Token copied to clipboard"}),o&&typeof o=="function"&&o())};return e(H,{permission:s,projectId:n,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(t.secret),size:"large",children:e(de,{})})},je=y("ul")({marginBottom:0}),tt=({token:t,permission:n,onRemove:s,project:o})=>{const[r,a]=u.useState(!1),{setToastData:i,setToastApiError:c}=M();return l(k,{children:[e(H,{permission:n,projectId:o,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>a(!0),size:"large",children:e(he,{})}),e(O,{open:r,onClick:async()=>{try{await s(),a(!1),i({type:"success",title:"API token removed"})}catch(b){c(pe(b))}},onClose:()=>a(!1),title:"Confirm deletion",children:l("div",{children:["Are you sure you want to delete the following API token?",e("br",{}),l(je,{children:[l("li",{children:[e("strong",{children:"username"}),":"," ",e("code",{children:t.username})]}),l("li",{children:[e("strong",{children:"type"}),": ",e("code",{children:t.type})]})]})]})})]})},Le=y("div")(()=>({maxWidth:"400px"})),Ue=y("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Fe=y(me)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),Me=y(ye)(({theme:t})=>({marginBottom:t.spacing(2),minWidth:"400px",[t.breakpoints.down("sm")]:{minWidth:"379px"}})),_=y("p")(({theme:t})=>({marginBottom:t.spacing(1)})),He=y("label")(({theme:t})=>({marginBottom:t.spacing(1)})),Oe=y(be)(({theme:t})=>({marginLeft:t.spacing(3)})),We=y(T)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),nt=({children:t,actions:n,handleSubmit:s,handleCancel:o})=>{var i;const{uiConfig:r}=E(),a=Boolean((i=r==null?void 0:r.flags)==null?void 0:i.UNLEASH_CLOUD);return l(Ue,{onSubmit:s,children:[e(C,{condition:a,show:l(N,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",e(U,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),t,l(We,{children:[n,e(Oe,{onClick:o,children:"Cancel"})]})]})},ot=t=>{var x;const{environments:n}=W(),s=(x=n==null?void 0:n.find(p=>p.enabled))==null?void 0:x.name,[o,r]=u.useState(""),[a,i]=u.useState("CLIENT"),[c,d]=u.useState([t||"*"]),[b,g]=u.useState(c),[f,h]=u.useState(),[D,S]=u.useState({});return u.useEffect(()=>{h(a==="ADMIN"?"*":s)},[a,s]),{username:o,type:a,projects:c,environment:f,setUsername:r,setTokenType:p=>{p==="ADMIN"?(i(p),g(c),d(["*"]),h("*")):(i(p),d(b),h(s))},setProjects:d,setEnvironment:h,getApiTokenPayload:()=>({username:o,type:a,environment:f,projects:c}),isValid:()=>{const p={};return o||(p.username="Username is required"),c.length===0&&(p.projects="At least one project is required"),S(p),Object.keys(p).length===0},clearErrors:p=>{if(p){const R={...D};delete R[p],S(R)}else S({})},errors:D}};var m=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(m||{});const st=({open:t,closeConfirm:n,token:s,type:o})=>l(O,{open:t,onClick:n,primaryButtonText:"Close",title:"New token created",children:[e(w,{variant:"body1",children:"Your new token has been created successfully."}),e(fe,{token:s}),e(C,{condition:o===m.FRONTEND,show:l(N,{sx:{mt:2},severity:"info",children:["By default, all ",m.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",e(F,{to:"/admin/cors",target:"_blank",children:"CORS origins configuration page"}),"."]})})]}),rt=({username:t,setUsername:n,errors:s,clearErrors:o})=>l(k,{children:[e(_,{children:"What would you like to call this token?"}),e(Fe,{value:t,name:"username",onChange:r=>n(r.target.value),label:"Token name",error:s.username!==void 0,errorText:s.username,onFocus:()=>o("username"),autoFocus:!0})]}),at=({type:t,setType:n})=>{const s=ge("projectId"),{uiConfig:o}=E(),r=[{key:m.CLIENT,label:`Server-side SDK (${m.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"}];return s||r.push({key:m.ADMIN,label:m.ADMIN,title:"Full access for managing Unleash"}),o.flags.embedProxyFrontend&&r.splice(1,0,{key:m.FRONTEND,label:`Client-side SDK (${m.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"}),e(Le,{children:l(Ce,{sx:{mb:2,width:"100%"},children:[e(He,{id:"token-type",children:"What do you want to connect?"}),e(Te,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:t,onChange:(a,i)=>n(i),children:r.map(({key:a,label:i,title:c})=>e(ke,{value:a,sx:{mb:1},control:e(Se,{sx:{ml:.75,alignSelf:"flex-start"}}),label:e(T,{children:l(T,{children:[e(w,{children:i}),e(w,{variant:"body2",color:"text.secondary",children:c})]})})},a))})]})})},lt=({type:t,environment:n,setEnvironment:s})=>{const{environments:o}=W(),r=t===m.ADMIN?[{key:"*",label:"ALL"}]:o.map(a=>({key:a.name,label:`${a.name.concat(a.enabled?"":" - deprecated")}`,title:a.name,disabled:!1}));return l(k,{children:[e(_,{children:"Which environment should the token have access to?"}),e(Me,{disabled:t===m.ADMIN,options:r,value:n,onChange:s,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:Ae,fullWidth:!0})]})},Ge=t=>t.map(n=>({...n.user,joinedAt:new Date(n.joinedAt),createdBy:n.createdBy})),it=t=>{const{data:n,error:s,mutate:o}=ve(G(`api/admin/groups/${t}`),Ke);return u.useMemo(()=>({group:n&&{...n,users:Ge((n==null?void 0:n.users)??[])},loading:!s&&!n,refetchGroup:()=>o(),error:s}),[n,s,o])},Ke=t=>fetch(t).then(K("Group")).then(n=>n.json()),ct=(t,n={})=>{const s=()=>{const d=G(`api/admin/roles/${t}`);return fetch(d,{method:"GET"}).then(K("project role")).then(b=>b.json())},{data:o,error:r}=Ie({},`api/admin/roles/${t}`,s,n),[a,i]=u.useState(!r&&!o),c=()=>{we(`api/admin/roles/${t}`)};return u.useEffect(()=>{i(!r&&!o)},[o,r]),{role:o||{},error:r,loading:a,refetch:c}};export{Je as A,Ye as B,Qe as C,lt as E,qe as M,tt as R,_ as S,m as T,et as a,ot as b,nt as c,rt as d,at as e,st as f,it as g,ct as h,Ge as m,Ze as u};
|
|
1
|
+
import{dX as $,c as L,j as e,H as E,f as l,A as N,N as z,c5 as V,U as X,F as k,C,a as T,X as Y,d8 as q,S as J,h as Q,i as Z,k as ee,W as P,bE as U,ar as te,ds as ne,bJ as oe,dY as se,s as y,aO as F,dH as re,l as B,dJ as A,r as u,I as ae,R as v,c6 as le,dn as ie,d as I,e as ce,a2 as M,aM as H,cl as de,dZ as ue,aY as he,a_ as O,a4 as pe,bS as me,c4 as ye,a9 as be,aj as W,T as w,dD as fe,cX as ge,a5 as Ce,dG as Te,bR as ke,dF as Se,d_ as Ae,aR as ve,aS as G,aT as K,cb as Ie,aU as we}from"./index-1d165488.js";const Ee=$(),Ye=Ee,Ne=L(e("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),qe=L(e("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"}),"MoreVert"),De=()=>{const{uiConfig:t}=E();return l(N,{severity:"info",children:[l("p",{children:["Read the"," ",e("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",e("strong",{children:"1 minute"})," before a new API key is activated."]}),e("br",{}),e("strong",{children:"API URL: "})," ",l("pre",{style:{display:"inline"},children:[t.unleashUrl,"/api/"]})]})},xe=["Icon","createdAt"],Re=["Icon","project","seenAt"],Je=({compact:t=!1,setHiddenColumns:n,columns:s,loading:o,rows:r,getTableProps:a,getTableBodyProps:i,headerGroups:c,globalFilter:d,prepareRow:b})=>{const g=z(V.breakpoints.down("md"));return X([{condition:g,columns:xe},{condition:t,columns:Re}],n,s),l(k,{children:[e(C,{condition:r.length>0,show:e(T,{sx:{mb:4},children:e(De,{})})}),e(T,{sx:{overflowX:"auto"},children:e(Y,{value:d,children:l(q,{...a(),children:[e(J,{headerGroups:c}),e(Q,{...i(),children:r.map(f=>(b(f),e(Z,{hover:!0,...f.getRowProps(),children:f.cells.map(h=>e(ee,{...h.getCellProps(),children:h.render("Cell")}))})))})]})})}),e(C,{condition:r.length===0&&!o,show:e(C,{condition:(d==null?void 0:d.length)>0,show:l(P,{children:["No tokens found matching “",d,"”"]}),elseShow:e(P,{children:l("span",{children:["No tokens available. Read ",e(U,{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},Qe=({path:t,permission:n,project:s})=>{const o=te();return e(ne,{Icon:oe,onClick:()=>o(t),"data-testid":se,permission:n,projectId:s,maxWidth:"700px",children:"New API token"})},Pe=y(F)(({theme:t})=>({textDecoration:"none",color:t.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),Be=({projects:t,project:n})=>{const{searchQuery:s}=re();let o=t&&Array.isArray(t)?t:n?[n]:[];return o.length===0?e(B,{children:e(A,{search:s,children:"*"})}):e(B,{children:o.map((r,a)=>l(u.Fragment,{children:[a>0&&", ",!r||r==="*"?e(A,{search:s,children:"*"}):e(Pe,{to:`/projects/${r}`,children:e(A,{search:s,children:r})})]},r))})},Ze=(t,n)=>{const s=u.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]),o=u.useMemo(()=>[{id:"Icon",width:"1%",Cell:()=>e(ae,{icon:e(Ne,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:v},{Header:"Type",accessor:"type",Cell:({value:h})=>e(v,{value:j[h.toLowerCase()].label,subtitle:j[h.toLowerCase()].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:h=>e(Be,{project:h.row.original.project,projects:h.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:v,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:le,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ie,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:n}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:b,setGlobalFilter:g,setHiddenColumns:f}=I.useTable({columns:o,data:t,initialState:s,sortTypes:ce,autoResetHiddenColumns:!1,disableSortRemove:!0},I.useGlobalFilter,I.useSortBy);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:b,setGlobalFilter:g,setHiddenColumns:f,columns:o}},j={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},et=({token:t,project:n,permission:s,track:o})=>{const{setToastData:r}=M(),a=i=>{ue(i)&&(r({type:"success",title:"Token copied to clipboard"}),o&&typeof o=="function"&&o())};return e(H,{permission:s,projectId:n,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(t.secret),size:"large",children:e(de,{})})},je=y("ul")({marginBottom:0}),tt=({token:t,permission:n,onRemove:s,project:o})=>{const[r,a]=u.useState(!1),{setToastData:i,setToastApiError:c}=M();return l(k,{children:[e(H,{permission:n,projectId:o,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>a(!0),size:"large",children:e(he,{})}),e(O,{open:r,onClick:async()=>{try{await s(),a(!1),i({type:"success",title:"API token removed"})}catch(b){c(pe(b))}},onClose:()=>a(!1),title:"Confirm deletion",children:l("div",{children:["Are you sure you want to delete the following API token?",e("br",{}),l(je,{children:[l("li",{children:[e("strong",{children:"username"}),":"," ",e("code",{children:t.username})]}),l("li",{children:[e("strong",{children:"type"}),": ",e("code",{children:t.type})]})]})]})})]})},Le=y("div")(()=>({maxWidth:"400px"})),Ue=y("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Fe=y(me)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),Me=y(ye)(({theme:t})=>({marginBottom:t.spacing(2),minWidth:"400px",[t.breakpoints.down("sm")]:{minWidth:"379px"}})),_=y("p")(({theme:t})=>({marginBottom:t.spacing(1)})),He=y("label")(({theme:t})=>({marginBottom:t.spacing(1)})),Oe=y(be)(({theme:t})=>({marginLeft:t.spacing(3)})),We=y(T)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),nt=({children:t,actions:n,handleSubmit:s,handleCancel:o})=>{var i;const{uiConfig:r}=E(),a=Boolean((i=r==null?void 0:r.flags)==null?void 0:i.UNLEASH_CLOUD);return l(Ue,{onSubmit:s,children:[e(C,{condition:a,show:l(N,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",e(U,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),t,l(We,{children:[n,e(Oe,{onClick:o,children:"Cancel"})]})]})},ot=t=>{var x;const{environments:n}=W(),s=(x=n==null?void 0:n.find(p=>p.enabled))==null?void 0:x.name,[o,r]=u.useState(""),[a,i]=u.useState("CLIENT"),[c,d]=u.useState([t||"*"]),[b,g]=u.useState(c),[f,h]=u.useState(),[D,S]=u.useState({});return u.useEffect(()=>{h(a==="ADMIN"?"*":s)},[a,s]),{username:o,type:a,projects:c,environment:f,setUsername:r,setTokenType:p=>{p==="ADMIN"?(i(p),g(c),d(["*"]),h("*")):(i(p),d(b),h(s))},setProjects:d,setEnvironment:h,getApiTokenPayload:()=>({username:o,type:a,environment:f,projects:c}),isValid:()=>{const p={};return o||(p.username="Username is required"),c.length===0&&(p.projects="At least one project is required"),S(p),Object.keys(p).length===0},clearErrors:p=>{if(p){const R={...D};delete R[p],S(R)}else S({})},errors:D}};var m=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(m||{});const st=({open:t,closeConfirm:n,token:s,type:o})=>l(O,{open:t,onClick:n,primaryButtonText:"Close",title:"New token created",children:[e(w,{variant:"body1",children:"Your new token has been created successfully."}),e(fe,{token:s}),e(C,{condition:o===m.FRONTEND,show:l(N,{sx:{mt:2},severity:"info",children:["By default, all ",m.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",e(F,{to:"/admin/cors",target:"_blank",children:"CORS origins configuration page"}),"."]})})]}),rt=({username:t,setUsername:n,errors:s,clearErrors:o})=>l(k,{children:[e(_,{children:"What would you like to call this token?"}),e(Fe,{value:t,name:"username",onChange:r=>n(r.target.value),label:"Token name",error:s.username!==void 0,errorText:s.username,onFocus:()=>o("username"),autoFocus:!0})]}),at=({type:t,setType:n})=>{const s=ge("projectId"),{uiConfig:o}=E(),r=[{key:m.CLIENT,label:`Server-side SDK (${m.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"}];return s||r.push({key:m.ADMIN,label:m.ADMIN,title:"Full access for managing Unleash"}),o.flags.embedProxyFrontend&&r.splice(1,0,{key:m.FRONTEND,label:`Client-side SDK (${m.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"}),e(Le,{children:l(Ce,{sx:{mb:2,width:"100%"},children:[e(He,{id:"token-type",children:"What do you want to connect?"}),e(Te,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:t,onChange:(a,i)=>n(i),children:r.map(({key:a,label:i,title:c})=>e(ke,{value:a,sx:{mb:1},control:e(Se,{sx:{ml:.75,alignSelf:"flex-start"}}),label:e(T,{children:l(T,{children:[e(w,{children:i}),e(w,{variant:"body2",color:"text.secondary",children:c})]})})},a))})]})})},lt=({type:t,environment:n,setEnvironment:s})=>{const{environments:o}=W(),r=t===m.ADMIN?[{key:"*",label:"ALL"}]:o.map(a=>({key:a.name,label:`${a.name.concat(a.enabled?"":" - deprecated")}`,title:a.name,disabled:!1}));return l(k,{children:[e(_,{children:"Which environment should the token have access to?"}),e(Me,{disabled:t===m.ADMIN,options:r,value:n,onChange:s,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:Ae,fullWidth:!0})]})},Ge=t=>t.map(n=>({...n.user,joinedAt:new Date(n.joinedAt),createdBy:n.createdBy})),it=t=>{const{data:n,error:s,mutate:o}=ve(G(`api/admin/groups/${t}`),Ke);return u.useMemo(()=>({group:n&&{...n,users:Ge((n==null?void 0:n.users)??[])},loading:!s&&!n,refetchGroup:()=>o(),error:s}),[n,s,o])},Ke=t=>fetch(t).then(K("Group")).then(n=>n.json()),ct=(t,n={})=>{const s=()=>{const d=G(`api/admin/roles/${t}`);return fetch(d,{method:"GET"}).then(K("project role")).then(b=>b.json())},{data:o,error:r}=Ie({},`api/admin/roles/${t}`,s,n),[a,i]=u.useState(!r&&!o),c=()=>{we(`api/admin/roles/${t}`)};return u.useEffect(()=>{i(!r&&!o)},[o,r]),{role:o||{},error:r,loading:a,refetch:c}};export{Je as A,Ye as B,Qe as C,lt as E,qe as M,tt as R,_ as S,m as T,et as a,ot as b,nt as c,rt as d,at as e,st as f,it as g,ct as h,Ge as m,Ze as u};
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{aB as gn,aC as hn,s as d,r as f,aD as mn,aE as fn,aF as pt,j as t,aG as yn,aH as Sn,c as jt,aI as F,aJ as j,aK as bn,f as c,aL as Cn,C as I,aM as Q,aN as le,aO as J,aP as me,aQ as vn,aR as Qe,aS as be,aT as ke,aU as Ze,u as et,aV as oe,F as M,aW as gt,aX as ht,aY as tt,aZ as ae,a_ as de,T as N,a$ as Ce,a2 as G,ar as ge,b0 as nt,b1 as ve,A as he,b2 as Nt,a4 as z,b3 as wn,b4 as Tn,b5 as xn,b6 as An,ap as we,b7 as En,b8 as ue,b9 as ee,m as $e,ba as In,bb as Rn,bc as Pe,a8 as Be,bd as zt,be as Wt,bf as at,bg as Fn,bh as kn,bi as $n,a as H,p as Pn,N as De,B as fe,bj as ot,a9 as re,bk as Bn,x as st,an as Ie,E as Dn,bl as rt,bm as Re,P as On,bn as Vn,bo as ne,bp as Mn,bq as Ln,D as _n,br as jn,bs as Nn,bt as zn,bu as Ut,bv as Wn,bw as Un,bx as qn,by as Hn,bz as Gn,bA as Yn,bB as Te,bC as Kn,bD as Jn,bE as it,bF as Xn,bG as Qn,as as qt,bH as Zn,w as Ht,af as ye,bI as ea,bJ as ta,bK as Ye,bL as Gt,bM as Yt,bN as se,bO as Ke,bP as na,ac as Kt,bQ as Jt,a3 as ct,ad as aa,bR as oa,bS as Xt,bT as sa,bU as ra,bV as Qt,bW as ia,H as lt,bX as ca,av as la,bY as ce,bZ as mt,b_ as da,b$ as ua,c0 as pa,c1 as ga,ak as dt,al as ha,V as ft,c2 as ma,c3 as fa,c4 as ya,c5 as Zt,d as Le,l as Sa,U as ba,g as Ca,S as va,h as wa,i as Ta,k as xa,I as Aa,c6 as Ea,c7 as Ia,c8 as yt,c9 as Ra,ca as en,cb as Fa,ae as ka,cc as St,cd as $a,ce as Pa,cf as Ba,cg as Da,ch as Oa,ci as Va,M as Ma,cj as La,ck as _a,cl as ja,cm as Na,cn as za,co as Wa}from"./index-c4e310cb.js";import{C as Oe,f as Ua,u as qa,U as Ha,E as Ga,V as Ya,a as Ka,b as Ja,c as Xa,T as Qa,d as Za,F as eo,A as to,W as no,e as ao,g as oo}from"./FeatureArchiveDialog-b81c4e16.js";import{S as so}from"./StrategyItemContainer-d93244f3.js";import{E as ro}from"./ExpandMore-4c20b51c.js";import{v as _e}from"./v4-a960c1f4.js";function io(e){return gn("MuiCardContent",e)}hn("MuiCardContent",["root"]);const co=["className","component"],lo=e=>{const{classes:n}=e;return Sn({root:["root"]},io,n)},uo=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),po=f.forwardRef(function(n,a){const o=mn({props:n,name:"MuiCardContent"}),{className:s,component:i="div"}=o,r=fn(o,co),l=pt({},o,{component:i}),u=lo(l);return t(uo,pt({as:i,className:yn(u.root,s),ownerState:l,ref:a},r))}),go=po,ho=jt(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),mo=jt(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),fo=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),yo=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=j(e,n);return a.name?t(fo,{children:t(bn,{title:"Event log",feature:n,displayInline:!0})}):null},So=d("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.primary.contrastText,backgroundColor:e.palette.background.alternative,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),bo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Co=d("div")({display:"flex",alignItems:"center"}),vo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),wo=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),bt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),Ct=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),To=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=j(e,n),{project:o,description:s,type:i}=a,r=vn(i);return t(So,{children:c(bo,{children:[c(Co,{"data-loading":!0,children:[t(r,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",c(vo,{children:[Cn(i||"")," toggle"]})]}),c(wo,{children:[c(bt,{"data-loading":!0,children:["Project: ",o]}),t(I,{condition:Boolean(s),show:c(bt,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(Ct,{children:[t("p",{children:s}),t(Q,{projectId:e,permission:le,component:J,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(me,{sx:l=>({color:l.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:c(Ct,{children:["No description."," ",t(Q,{projectId:e,permission:le,component:J,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(me,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},vt={lastHourUsage:[],seenApplications:[]},xo=(e,n,a={})=>{const o=async()=>{const m=be(`api/admin/client-metrics/features/${n}`),g=await fetch(m,{method:"GET"}).then(ke("feature metrics"));return g.ok?g.json():vt},s=`${e}_${n}_metrics`,{data:i,error:r}=Qe(s,o,{...a}),[l,u]=f.useState(!r&&!i),p=()=>{Ze(s)};return f.useEffect(()=>{u(!r&&!i)},[i,r]),{metrics:i||vt,error:r,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:s}},Ao=e=>({yes:0,no:0,environment:e,timestamp:""}),Eo=(e,n)=>e.map(a=>n.lastHourUsage.find(s=>s.environment===a.name)||Ao(a.name)),Io=({enabled:e,className:n})=>{const a=et(),o=e?"Environment enabled":"Environment disabled",s={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)},i={fill:a.palette.common.white,width:"16px",height:"16px"};return t("div",{style:s,className:n,children:t(mo,{style:i,titleAccess:o})})},tn=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),Ro=({onRemove:e,onClose:n,isOpen:a})=>t(de,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(tn,{})}),Fo=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),ko=({onRemove:e,onClose:n,isOpen:a})=>c(de,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(tn,{}),t(Fo,{children:t(N,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(N,{fontWeight:"bold",children:"Remove strategy"})]}),$o=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{deleteStrategyFromFeature:s}=Ce(),{setToastData:i,setToastApiError:r}=G(),l=ge(),{refetchFeature:u}=j(e,n);return async m=>{try{m.preventDefault(),await s(e,n,a,o),i({title:"Strategy deleted",type:"success"}),u(),l(Nt(e,n))}catch(g){r(z(g))}}},Po=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{addChange:s}=nt(),{refetch:i}=ve(e),{setToastData:r,setToastApiError:l}=G();return async p=>{try{p.preventDefault(),await s(e,a,{action:"deleteStrategy",feature:n,payload:{id:o}}),r({title:"Changes added to the draft!",type:"success"}),await i()}catch(m){l(z(m))}}},Bo=({projectId:e,featureId:n,environmentId:a,strategyId:o,disabled:s,icon:i})=>{const[r,l]=f.useState(!1),{isChangeRequestConfigured:u}=oe(e),p=$o({featureId:n,projectId:e,strategyId:o,environmentId:a}),m=Po({featureId:n,projectId:e,strategyId:o,environmentId:a});return c(M,{children:[t(I,{condition:Boolean(i),show:t(Q,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:s,permission:gt,"data-testid":ht,tooltipProps:{title:"Remove strategy"},type:"button",children:t(tt,{})}),elseShow:t(ae,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:s,permission:gt,"data-testid":ht,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(I,{condition:u(a),show:t(ko,{isOpen:r,onClose:()=>l(!1),onRemove:async g=>{await m(g),l(!1)}}),elseShow:t(Ro,{isOpen:r,onClose:()=>l(!1),onRemove:p})})]})},Do=e=>(n,a,o)=>(o.revalidateOnFocus=!1,o.revalidateIfStale=!1,o.revalidateOnReconnect=!1,e(n,a,o));var Oo=wn(Qe,Do);const nn=(e,n)=>{const{refetchFeature:a}=j(e,n),o=Tn(e,n),{data:s,error:i,mutate:r}=Oo(["useFeatureImmutable",o],()=>xn(o)),l=f.useCallback(async()=>{await r(),await a()},[r,a]);return{feature:(s==null?void 0:s.body)||An,refetchFeature:l,loading:!i&&!s,status:s==null?void 0:s.status,error:i}},ut=(e,n,a)=>{const{setToastData:o,setToastApiError:s}=G(),{addChange:i}=nt(),{refetch:r}=ve(e),[l,u]=f.useState({isOpen:!1}),p=f.useCallback((x,A,y)=>{u({featureName:n,environment:x,fromEnvironment:y,strategy:A,isOpen:!0})},[]),m=f.useCallback((x,A,y)=>{u({featureName:n,environment:x,fromEnvironment:y,strategies:A,isOpen:!0})},[]),g=f.useCallback(()=>{u({isOpen:!1})},[]),S=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),r(),u({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(x){s(z(x)),u({isOpen:!1})}},[i]),C=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(x=>i(e,l.environment,{feature:l.featureName,action:a,payload:x}))),r(),u({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(x){s(z(x)),u({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:m,onChangeRequestAddStrategyClose:g,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategiesConfirm:C,changeRequestDialogDetails:l}},Vo=({payload:e,fromEnvironment:n,environment:a})=>c(N,{children:[c("strong",{children:["Copy ",we((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),Mo=({environmentId:e,environments:n,strategy:a})=>{const o=F("projectId"),s=F("featureId"),[i,r]=f.useState(null),l=Boolean(i),{addStrategyToFeature:u}=Ce(),{setToastData:p,setToastApiError:m}=G(),{refetchFeature:g}=j(o,s),{refetchFeature:S}=nn(o,s),C=()=>{r(null)},x=En(o),{isChangeRequestConfigured:A}=oe(o),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:v,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:R}=ut(o,s,"addStrategy"),P=async $=>{const{id:O,...B}={...a,targetEnvironment:$};if(A($)){await w($,{id:O,...B},e);return}try{await u(o,s,$,a),g(),S(),p({title:"Strategy created",text:`Successfully copied a strategy to ${$}`,type:"success"})}catch(U){m(z(U))}C()},D=n.some($=>x(ue,$));return c("div",{children:[t(Oe,{isOpen:y.isOpen,onClose:v,environment:y==null?void 0:y.environment,onConfirm:R,messageComponent:t(Vo,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(ee,{title:`Copy to another environment${D?"":" (Access denied)"}`,children:t("div",{children:t($e,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,onClick:$=>{r($.currentTarget)},"data-testid":In,disabled:!D,children:t(Rn,{})})})}),t(Pe,{id:"basic-menu",anchorEl:i,open:l,onClose:C,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map($=>{const O=x(ue,$);return t(ee,{title:O?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Be,{onClick:()=>P($),disabled:!O,children:[t(I,{condition:!O,show:t(zt,{children:t(Wt,{fontSize:"small"})})}),c(at,{children:["Copy to ",$]})]})})},$)})})]})},Lo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:o,otherEnvironments:s,orderNumber:i,headerChildren:r})=>{const l=F("projectId"),u=F("featureId"),p=Fn(l,u,e,n.id);return t(so,{strategy:n,onDragStart:a,onDragEnd:o,orderNumber:i,actions:c(M,{children:[r,t(I,{condition:Boolean(s&&(s==null?void 0:s.length)>0),show:()=>t(Mo,{environmentId:e,environments:s,strategy:n})}),t(Q,{permission:kn,environmentId:e,projectId:l,component:J,to:p,tooltipProps:{title:"Edit strategy"},children:t(me,{})}),t(Bo,{projectId:l,featureId:u,environmentId:e,strategyId:n.id,icon:!0})]}),children:t($n,{strategy:n})})},_o=(e,n,a,o)=>{const{data:s}=ve(e),i=s==null?void 0:s.find(u=>u.environment===a),r=i==null?void 0:i.features.find(u=>u.name===n);return r==null?void 0:r.changes.find(u=>u.action==="updateStrategy"||u.action==="deleteStrategy"?u.payload.id===o:!1)},jo=({strategy:e,index:n,environmentName:a,otherEnvironments:o,isDragging:s,onDragStartRef:i,onDragOver:r,onDragEnd:l})=>{const u=F("projectId"),p=F("featureId"),m=f.useRef(null),g=_o(u,p,a,e.id);return c(H,{ref:m,onDragOver:r(m,n),sx:{opacity:s?"0.5":"1"},children:[t(I,{condition:n>0,show:t(Pn,{text:"OR"})}),t(Lo,{strategy:e,environmentId:a,otherEnvironments:o,onDragStart:i(m,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(No,{change:g})})]},e.id)},No=({change:e})=>{const n=et();return De(n.breakpoints.down("sm"))?null:c(H,{sx:{mr:1.5},children:[t(I,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(fe,{color:"warning",children:"Modified in draft"})}),t(I,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(fe,{color:"error",children:"Deleted in draft"})})]})},zo=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.divider}})),Wo=d("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.envAccordion.expanded,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),an=({children:e})=>t(zo,{children:t(Wo,{children:e})}),Uo=({environmentId:e,environments:n,onClick:a})=>{const o=F("projectId"),[s,i]=f.useState(null),r=Boolean(s),{hasAccess:l}=f.useContext(ot),u=n.some(p=>l(ue,o,p));return c("div",{children:[t(ee,{title:u?"":"(Access denied)",children:t("div",{children:t(re,{id:`copy-all-strategies-${e}`,"aria-controls":r?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":r?"true":void 0,onClick:p=>{i(p.currentTarget)},disabled:!u,variant:"outlined",children:"Copy from another environment"})})}),t(Pe,{id:"basic-menu",anchorEl:s,open:r,onClose:()=>{i(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(p=>{const m=l(ue,o,p);return t(ee,{title:m?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Be,{onClick:()=>a(p),disabled:!m,children:[t(I,{condition:!m,show:t(zt,{children:t(Wt,{fontSize:"small"})})}),c(at,{children:["Copy from ",p]})]})})},p)})})]})},qo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Ho=({payload:e,fromEnvironment:n,environment:a})=>c(qo,{children:[t(N,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(o=>c(N,{children:[c("strong",{children:[we((o==null?void 0:o.name)||"")," strategy"," "]})," "]})),c(N,{children:["from ",n," to ",a]})]}),Go=({payload:e,environment:n})=>c(M,{children:[t(N,{component:"span",children:"Add "}),c("strong",{children:[we((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),Yo=d(Bn)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),wt=({title:e,children:n,featureId:a,projectId:o,environmentId:s,strategy:i,Icon:r,onAfterAddStrategy:l})=>{const{addStrategyToFeature:u}=Ce(),{setToastApiError:p}=G(),{isChangeRequestConfigured:m}=oe(o),{changeRequestDialogDetails:g,onChangeRequestAddStrategy:S,onChangeRequestAddStrategyConfirm:C,onChangeRequestAddStrategyClose:x}=ut(o,a,"addStrategy");return c(M,{children:[t(Yo,{variant:"outlined",children:c(go,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(N,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(N,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(H,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(ae,{permission:ue,projectId:o,environmentId:s,variant:"outlined",size:"small",onClick:async()=>{try{m(s)?S(s,i):(await u(o,a,s,i),l())}catch(y){p(z(y))}},children:"Use template"})})]})}),t(Oe,{isOpen:g.isOpen,onClose:x,environment:g==null?void 0:g.environment,onConfirm:C,messageComponent:t(Go,{environment:s,payload:g.strategy})})]})},Ko=d("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),Jo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Xo=d(st)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Qo=d(J)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),Zo=({projectId:e,featureId:n,environmentId:a,strategy:o})=>{const s=Ie(o.name),i=we(o.name),r=Ua(e,n,a,o.name);return c(Qo,{to:r,children:[t(Ko,{children:t(s,{})}),c("div",{children:[t(Xo,{text:o.displayName||i,maxWidth:"200",maxLength:25}),t(Jo,{children:o.description})]})]})},es=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:o}=Dn(),s=f.useMemo(()=>o.filter(i=>!i.deprecated),[o]);return t(rt,{dense:!0,children:s.map(i=>t(Re,{children:t(Zo,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name))})},Je=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,matchWidth:i})=>{const[r,l]=f.useState(),u=Boolean(r),p=u?"FeatureStrategyMenuPopover":void 0,m=()=>{l(void 0)};return c("div",{onClick:S=>S.stopPropagation(),children:[t(ae,{permission:ue,projectId:n,environmentId:o,onClick:S=>{l(S.currentTarget)},"aria-labelledby":p,variant:s,sx:{minWidth:i?"282px":"auto"},children:e}),t(On,{id:p,open:u,anchorEl:r,onClose:m,onClick:m,children:t(es,{projectId:n,featureId:a,environmentId:o})})]})},ts=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),ns=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),as=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),os=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:o}=Ce(),{setToastData:s,setToastApiError:i}=G(),{refetchFeature:r}=j(e,n),{refetchFeature:l}=nn(e,n),{feature:u}=j(e,n),p=u==null?void 0:u.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:m}=oe(e),{changeRequestDialogDetails:g,onChangeRequestAddStrategies:S,onChangeRequestAddStrategiesConfirm:C,onChangeRequestAddStrategyClose:x}=ut(e,n,"addStrategy"),A=(w=!1)=>{r(),l(),s({title:w?"Strategies created":"Strategy created",text:w?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async w=>{var P;const R=((P=p==null?void 0:p.find(D=>D.name===w))==null?void 0:P.strategies)||[];if(m(a)){await S(a,R,w);return}try{await Promise.all(R.map(D=>{const{id:$,...O}={...D,environment:a};return o(e,n,a,O)})),A(!0)}catch(D){i(z(D))}},v=p&&p.length>0;return c(M,{children:[t(Oe,{isOpen:g.isOpen,onClose:x,environment:g==null?void 0:g.environment,onConfirm:C,messageComponent:t(Ho,{fromEnvironment:g.fromEnvironment,payload:g.strategies})}),c(ts,{children:[t(ns,{children:"You have not defined any strategies yet."}),c(as,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(J,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(H,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(Je,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:v}),t(I,{condition:v,show:t(Uo,{environmentId:a,environments:p.map(w=>w.name),onClick:y})})]}),t(H,{sx:{width:"100%",mt:3},children:t(an,{children:"Or use a strategy template"})}),c(H,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(wt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:A,Icon:Ie("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(wt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:A,Icon:Ie("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:u.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},ss=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),rs=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),is=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const o=F("projectId"),s=F("featureId"),{setStrategiesSortOrder:i}=Ce(),{setToastData:r,setToastApiError:l}=G(),{refetchFeature:u}=j(o,s),[p,m]=f.useState((e==null?void 0:e.strategies)||[]),[g,S]=f.useState(null);if(f.useEffect(()=>{m((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const C=async v=>{try{await i(o,s,e.name,v),u(),r({title:"Order of strategies updated",type:"success"})}catch(w){l(z(w))}},x=(v,w)=>R=>{var P;S({id:p[w].id,index:w,height:((P=v.current)==null?void 0:P.offsetHeight)||0}),v!=null&&v.current&&(R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/html",v.current.outerHTML),R.dataTransfer.setDragImage(v.current,20,20))},A=v=>(w,R)=>P=>{if(g===null||w.current===null||g.index===R||v===g.id)return;const{top:D,bottom:$}=w.current.getBoundingClientRect(),O=P.clientY-D<g.height,B=$-P.clientY<g.height,U=g.index>R;if(O&&U||B&&!U){const Y=[...p],K=Y.splice(g.index,1)[0];Y.splice(R,0,K),m(Y),S({...g,index:R})}},y=()=>{S(null),C(p.map((v,w)=>({id:v.id,sortOrder:w})))};return t(ss,{children:c(rs,{children:[t(I,{condition:p.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(I,{condition:p.length>0,show:t(M,{children:p.map((v,w)=>t(jo,{strategy:v,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(g==null?void 0:g.id)===v.id,onDragStartRef:x,onDragOver:A(v.id),onDragEnd:y},v.id))}),elseShow:t(os,{projectId:o,featureId:s,environmentId:e.name})})]})})},on=(e,n)=>e===0?0:Math.round(n/e*100);var Ve={},Me={};Object.defineProperty(Me,"__esModule",{value:!0});Me.defaultOptions=void 0;Me.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var pe={};Object.defineProperty(pe,"__esModule",{value:!0});pe.roundTo=pe.parseValue=void 0;function cs(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}pe.parseValue=cs;function ls(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}pe.roundTo=ls;Object.defineProperty(Ve,"__esModule",{value:!0});Ve.millify=void 0;const je=Me,Tt=pe,xt=1e3;function*At(e){let n=xt;for(;;){const a=e/n;if(a<1)return;yield a,n*=xt}}function sn(e,n){var a;const o=n?Object.assign(Object.assign({},je.defaultOptions),n):je.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let s;try{s=Tt.parseValue(e)}catch(C){return C instanceof Error&&console.warn(`WARN: ${C.message} (millify)`),String(e)}const i=s<0?"-":"";s=Math.abs(s);let r=0;for(const C of At(s))s=C,r+=1;if(r>=o.units.length)return e.toString();let u=Tt.roundTo(s,o.precision);for(const C of At(u))u=C,r+=1;const p=(a=o.units[r])!==null&&a!==void 0?a:"",m=o.lowercase?p.toLowerCase():p,g=o.space?" ":"",S=u.toString().replace(je.defaultOptions.decimalSeparator,o.decimalSeparator);return`${i}${S}${g}${m}`}Ve.millify=sn;var ds=Ve.default=sn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let o,s=!1;e<n?o=e.toLocaleString():(o=ds(e,{precision:a}),s=!0);const i=t("span",{"data-testid":Vn,children:o});return t(I,{condition:s,show:t(ee,{title:e.toLocaleString(),arrow:!0,children:i}),elseShow:i})},Ne=d("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),ze=d("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),We=d("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),Ue=d("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.divider,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),rn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:o,tableSectionId:s})=>{const i=a===1?"in the last hour":`in the last ${a} hours`;return c(ne,{container:!0,spacing:2,id:o,"aria-describedby":s,"aria-label":"Feature metrics summary",component:"section",children:[t(ne,{item:!0,xs:12,sm:4,children:c(Ne,{children:[t(ze,{children:"Exposure"}),t(We,{children:t(Fe,{value:e})}),c(Ue,{children:["Total exposure of the feature in the environment"," ",i,"."]})]})}),t(ne,{item:!0,xs:12,sm:4,children:c(Ne,{children:[t(ze,{children:"Exposure %"}),c(We,{children:[on(e+n,e),"%"]}),c(Ue,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(ne,{item:!0,xs:12,sm:4,children:c(Ne,{children:[t(ze,{children:"Requests"}),t(We,{children:t(Fe,{value:e+n})}),c(Ue,{children:["Total requests for the feature in the environment"," ",i,"."]})]})})]})},us=({environmentMetric:e})=>e?c(M,{children:[t(an,{children:"Feature toggle exposure"}),t("div",{children:t(rn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Et=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),It=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Rt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Ft=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),ps=d(Mn)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),gs=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),hs=({environmentMetric:e,disabled:n=!1})=>{const a=Ln();if(!e)return null;const o=e.yes+e.no,s=on(o,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Et,{children:[c(It,{children:[c(Rt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[s,"%"]}),c(Ft,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(ps,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Et,{children:[c(It,{children:[c(Rt,{children:[s,"%"]}),c(Ft,{children:["The feature has been requested"," ",c("b",{children:[t(Fe,{value:o})," times"]})," ","and exposed"," ",c("b",{children:[t(Fe,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(gs,{"data-loading":!0,children:t(_n,{percentage:s,size:"3rem"})})]})},ms=({strategyName:e})=>{const n=Ie(e);return t(ee,{title:we(e),arrow:!0,children:t(fs,{children:t(n,{})})})},fs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.action.disabled,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),ys=({strategies:e})=>e!=null&&e.length?t(Ss,{"aria-label":"Feature strategies",children:e.map(n=>t(bs,{children:t(ms,{strategyName:n.name})},n.id))}):null,Ss=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),bs=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Cs=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:n?e.palette.background.paper:e.palette.envAccordion.disabled})),vs=d(jn)({boxShadow:"none",background:"none"}),ws=d(Nn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Ts=d(zn,{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)}})),xs=d(is)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),As=d("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:n?e.palette.text.primary:e.palette.text.secondary})),Es=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Is=d(Io)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Rs=d(st)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Fs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),ks=({env:e})=>{var p;const n=F("projectId"),a=F("featureId"),{metrics:o}=xo(n,a),{feature:s}=j(n,a),{value:i}=Ut(),l=Eo(s==null?void 0:s.environments,o).find(m=>m.environment===e.name),u=s==null?void 0:s.environments.find(m=>m.name===e.name);return t(I,{condition:!Boolean(new Set(i.hiddenEnvironments).has(e.name)),show:t(Cs,{enabled:e.enabled,children:c(vs,{"data-testid":`${Wn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(ws,{expandIcon:t(ro,{titleAccess:"Toggle"}),children:[c(As,{"data-loading":!0,enabled:e.enabled,children:[c(Es,{children:[t(Is,{enabled:e.enabled}),t("div",{children:t(Rs,{text:e.name,maxWidth:"100",maxLength:15})}),t(I,{condition:!e.enabled,show:t(fe,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),c(Fs,{children:[t(Je,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(ys,{strategies:u==null?void 0:u.strategies})]})]}),t(hs,{environmentMetric:l,disabled:!e.enabled})]}),c(Ts,{enabled:e.enabled,children:[t(xs,{featureEnvironment:u,isDisabled:!e.enabled,otherEnvironments:s==null?void 0:s.environments.map(({name:m})=>m).filter(m=>m!==e.name)}),t(I,{condition:(((p=u==null?void 0:u.strategies)==null?void 0:p.length)||0)>0,show:c(M,{children:[t(H,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Je,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(us,{environmentMetric:l})]})})]})]})})})},$s=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=j(e,n);if(!a)return null;const{environments:o}=a;return t(M,{children:o==null?void 0:o.map(s=>t(ks,{env:s},s.name))})},Ps=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Bs=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Ds=({feature:e,header:n})=>{const{locationSettings:a}=Un();return c(Ps,{children:[n,c("div",{"data-loading":!0,children:[t(Bs,{children:"Created at:"}),t("span",{children:qn(Hn(e.createdAt),a.locale)})]})]})},Os=d($e,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.action.active:e.palette.action.focus,"&:hover":{color:e.palette.action.active}})),Vs=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Os,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(I,{condition:n.has(e.name),show:t(Gn,{}),elseShow:t(Yn,{})})}),Ms=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Ls=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),_s=({environment:e,callback:n,showInfoBox:a,children:o,hiddenEnvironments:s,setHiddenEnvironments:i})=>{const{name:r,enabled:l}=e,u=F("projectId"),p=F("featureId"),{toggleFeatureEnvironmentOn:m,toggleFeatureEnvironmentOff:g}=Te(),{refetchFeature:S}=j(u,p),{setToastData:C,setToastApiError:x}=G(),{isChangeRequestConfigured:A}=oe(u),{onChangeRequestToggle:y,onChangeRequestToggleClose:v,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:R}=qa(u),P=async()=>{try{await m(u,p,r),C({type:"success",title:`Available in ${r}`,text:`${p} is now available in ${r} based on its defined strategies.`}),S(),n&&n()}catch(B){B instanceof Error&&B.message===Ga?a():x(z(B))}},D=async()=>{try{await g(u,p,r),C({type:"success",title:`Unavailable in ${r}`,text:`${p} is unavailable in ${r} and its strategies will no longer have any effect.`}),S(),n&&n()}catch(B){x(z(B))}},$=async B=>{if(A(r)){B.preventDefault(),y(p,r,!l);return}if(l){await D();return}await P()},O=c(M,{children:[" ",c("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(st,{text:r,maxWidth:"120",maxLength:15})]});return c(Ms,{children:[c(Ls,{children:[t(Kn,{tooltip:l?`Disable feature in ${r}`:`Enable feature in ${r}`,permission:Jn,projectId:u,checked:l,onChange:$,environmentId:r}),o??O]}),t(Vs,{environment:e,hiddenEnvironments:s,setHiddenEnvironments:i}),t(Oe,{isOpen:R.isOpen,onClose:v,environment:R==null?void 0:R.environment,onConfirm:w,messageComponent:t(Ha,{enabled:R==null?void 0:R.enabled,featureName:R==null?void 0:R.featureName,environment:R.environment})})]})},js=d("div")(({theme:e})=>({padding:e.spacing(3)})),Ns=d("div")(()=>({display:"flex",flexDirection:"column"})),zs=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Ws=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),kt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Us=d(it)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),qs=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:o})=>{const[s,i]=f.useState(!1),[r,l]=f.useState(""),u=e.environments.some(p=>{var m;return p.enabled&&((m=p.variants)==null?void 0:m.length)});return c(js,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const m=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,g=p.variants??[],S=g.length>0&&c(M,{children:[t(kt,{}),t(ee,{title:"View variants",arrow:!0,describeChild:!0,children:t(Us,{component:J,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:g.length===1?"1 variant":`${g.length} variants`})})]}),C=p.enabled&&g.length===0&&u;return t(_s,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:o,showInfoBox:()=>{l(p.name),i(!0)},children:c(Ns,{children:[t(zs,{children:p.name}),c(Ws,{children:[m,S,t(I,{condition:C,show:c(M,{children:[t(kt,{}),t(Ya,{})]})})]})]})},p.name)}),t(Ka,{open:s,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},cn=(e,n={})=>{const a=async()=>{const p=be(`api/admin/features/${e}/tags`);return(await fetch(p,{method:"GET"}).then(ke("Tags"))).json()},o=`api/admin/features/${e}/tags`,{data:s,error:i}=Xn(Boolean(e),{tags:[]},o,a,n),[r,l]=f.useState(!i&&!s),u=()=>{Ze(o)};return f.useEffect(()=>{l(!i&&!s)},[s,i]),{tags:(s==null?void 0:s.tags)||[],error:i,loading:r,refetch:u}},Hs=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),qe=e=>e.map(n=>({title:n.value})),$t=(e,n)=>e.map(a=>({value:a.title,type:n})),ln=({open:e,setOpen:n})=>{const{tagTypes:a}=Qn(),o=F("featureId"),{createTag:s}=Ja(),{updateFeatureTags:i,loading:r}=Te(),{tags:l,refetch:u,loading:p}=cn(o),{setToastData:m}=G(),[g,S]=f.useState({name:"simple",description:"Simple tag to get you started",icon:""}),C=r||p,[x,A]=f.useState(0),{trackEvent:y}=qt(),[v,w]=f.useState(qe(l.filter(h=>h.type===g.name))),{tags:R,refetch:P}=Xa(g.name),D=f.useMemo(()=>qe(R),[R]);f.useEffect(()=>{l&&g&&w(qe(l.filter(h=>h.type===g.name)))},[JSON.stringify(l),g]);const $=()=>{n(!1),w([])};function O(h,b){const E=h.filter(L=>L.type===g.name).filter(L=>!b.find(_=>L.value===_.value&&L.type===_.type)),V=b.filter(L=>L.type===g.name).filter(L=>!h.find(_=>L.value===_.value&&L.type===_.type));return A(E.length+V.length),{added:E,removed:V}}const B=h=>h.filter(b=>!b.title.startsWith("Create")),U=async(h,b)=>{try{await i(o,{addedTags:h,removedTags:b}),await u()}catch(E){const V=z(E);m({type:"error",title:"Failed to add tag",text:V,confetti:!1})}},Y=(h,b)=>{let E="We successfully";return h>0&&(E=E.concat(` added ${h} new tag${h>1?"s":""}`)),h>0&&b>0&&(E=E.concat(" and ")),b>0&&(E=E.concat(` removed ${b} tag${b>1?"s":""}`)),E},K=async h=>{h.preventDefault();const b=$t(B(v),g.name),{added:E,removed:V}=O(b,l);x>0&&(await U(E,V),x>1&&y("suggest_tags",{props:{eventType:"multiple_tags_added"}}),x>0&&m({type:"success",title:`Updated tag${E.length>1?"s":""} to toggle`,text:Y(E.length,V.length),confetti:!0})),A(0),w([]),n(!1)},Z=(h,b)=>{b!=null&&typeof b!="string"&&(h.preventDefault(),S(b),w([]),A(0))},te=(h,b,E)=>{const V=Zn(b);E==="selectOption"&&b.forEach((_,q)=>{if(typeof _!="string"&&_.inputValue&&_.inputValue!==""){const xe={value:_.inputValue,type:g.name};s(xe).then(()=>{y("suggest_tags",{props:{eventType:"tag_created"}}),P()}),_.title=_.inputValue,_.inputValue="",V[q]=_}});const L=$t(B(V),g.name);O(L,l),w(V)},T="add-tag-form";return t(de,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:K,disabledPrimaryButton:C||x===0,onClose:$,formId:T,children:c(M,{children:[t(N,{paragraph:!0,sx:{marginBottom:h=>h.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:T,onSubmit:K,children:c(Hs,{children:[t(Qa,{options:a,value:g,onChange:Z}),t(Za,{options:D,existingTags:l,tagType:g,selectedOptions:v,onChange:te})]})})]})})},Gs=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Ys=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Ks=d(Ht)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Js=d(ye)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Xs=d(re)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Qs=({feature:e,header:n})=>{const{tags:a,refetch:o}=cn(e.name),{deleteTagFromFeature:s}=Te(),[i,r]=f.useState(!1),[l,u]=f.useState(!1),[p,m]=f.useState(),{setToastData:g,setToastApiError:S}=G(),{hasAccess:C}=f.useContext(ot),x=C(le,e.project),A=async()=>{if(p)try{await s(e.name,p.type,p.value),o(),g({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){S(z(y))}};return c(Gs,{children:[n,t(Ys,{children:a.map(y=>{const v=`${y.type}:${y.value}`;return t(Ks,{label:v,deleteIcon:t(ea,{titleAccess:"Remove"}),onDelete:x?()=>{u(!0),m(y)}:void 0},v)})}),t(I,{condition:x,show:c(M,{children:[t(I,{condition:a.length>0,show:t(Js,{})}),t(Xs,{"data-loading":!0,variant:"outlined",startIcon:t(ta,{}),onClick:()=>r(!0),children:"Add new tag"})]})}),t(ln,{open:i,setOpen:r}),c(de,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{u(!1),m(void 0)},onClick:()=>{u(!1),A(),m(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},Zs=d("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),He=d("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),er=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=F("projectId"),o=F("featureId"),{feature:s}=j(a,o);return c(Zs,{children:[t(qs,{header:c(He,{"data-loading":!0,children:["Enabled in environments (",s.environments.filter(({enabled:i})=>i).length,")",t(Ye,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:s,hiddenEnvironments:e,setHiddenEnvironments:n}),t(ye,{}),t(Ds,{header:t(He,{"data-loading":!0,children:"Feature toggle details"}),feature:s}),t(ye,{}),t(Qs,{header:t(He,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:s})]})},tr=()=>{const{trackEvent:e}=qt(),{value:n,setValue:a}=Ut(),[o,s]=f.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:o,setHiddenEnvironments:r=>{a(l=>{const u=new Set(l.hiddenEnvironments);return u.has(r)?(u.delete(r),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(u.add(r),e("hidden_environment",{props:{eventType:"environment hidden"}})),s(u),{...n,hiddenEnvironments:u}})}}},nr=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),ar=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),or=()=>{const e=ge(),n=F("projectId"),a=F("featureId"),o=Nt(n,a),{hiddenEnvironments:s,setHiddenEnvironments:i}=tr(),r=()=>e(o);return Gt(a),c(nr,{children:[c("div",{children:[t(To,{}),t(er,{hiddenEnvironments:s,setHiddenEnvironments:i})]}),t(ar,{children:t($s,{})}),c(Yt,{children:[t(se,{path:"strategies/create",element:t(Ke,{label:"Create feature strategy",onClose:r,open:!0,children:t(eo,{})})}),t(se,{path:"strategies/edit",element:t(Ke,{label:"Edit feature strategy",onClose:r,open:!0,children:t(na,{})})})]})]})},sr=({values:e=[],updateValues:n,placeholder:a="",error:o,...s})=>{const i=l=>{const p=l.target.value.split(/,\s?/).map(m=>m.trim());n(p)},r=l=>{if(l.key==="Backspace"){const u=l.target.value;if(u.endsWith(", ")){l.preventDefault();const p=u.slice(0,-2);n(p.split(/,\s*/))}}};return t(Kt,{...s,error:o,placeholder:a,value:e?e.join(", "):"",onKeyDown:r,onChange:i,style:{width:"100%"},variant:"outlined",size:"small"})},rr=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"}}})),ir=d(Jt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),cr=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),lr=d(sr)(()=>({width:"100%"})),dr=d(Kt)(()=>({width:"100%"})),ur=({overrides:e,overridesDispatch:n})=>{const{context:a}=ct(),o=a.map(({name:r})=>({key:r,label:r})),s=r=>l=>{n({type:"UPDATE_VALUES_AT",payload:[r,l]})},i=r=>(l,u)=>{l==null||l.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[r,u||[]]})};return t(M,{children:e.map((r,l)=>{var g;const u=a.find(({name:S})=>S===r.contextName),p=((g=u==null?void 0:u.legalValues)==null?void 0:g.map(({value:S})=>S))||[],m=r.values.filter(S=>p.includes(S));return c(rr,{children:[t(ir,{id:"override-context-name",name:"contextName",label:"Context Field",value:r.contextName,options:o,onChange:S=>n({type:"UPDATE_TYPE_AT",payload:[l,S.target.value]})}),c(cr,{children:[t(I,{condition:Boolean(p&&p.length>0),show:t(aa,{multiple:!0,id:`override-select-${l}`,isOptionEqualToValue:(S,C)=>S===C,options:p,onChange:i(l),getOptionLabel:S=>S,value:m,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:S=>t(dr,{...S,variant:"outlined",label:"Legal values"})}),elseShow:t(lr,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:r.values,updateValues:s(l)})}),t(ee,{title:"Remove",arrow:!0,children:t($e,{onClick:S=>{S.preventDefault(),n({type:"REMOVE",payload:l})},children:t(tt,{})})})]})]},`override=${l}`)})})},pr=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((r,l)=>l!==n.payload);case"UPDATE_VALUES_AT":const[a,o]=n.payload;return e.map((r,l)=>l===a?{...r,values:o}:r);case"UPDATE_TYPE_AT":const[s,i]=n.payload;return e.map((r,l)=>l===s?{...r,contextName:i}:r)}},gr=(e=[])=>f.useReducer(pr,e);var X=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(X||{});const hr=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})),mr=d(ee)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),dn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Pt=d(dn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),fr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),yr=d(oa)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),Sr=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex","& > div":{width:"100%"}})),Bt=d(Xt)(()=>({width:"100%"})),br=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),Cr=d(Xt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),vr=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),un=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%"}}})),wr=d(un)({alignItems:"end",justifyContent:"space-between"}),Tr=d(Jt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),xr=d(re)(({theme:e})=>({marginTop:e.spacing(-1),marginLeft:e.spacing(-1)})),Ar=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Er={type:"string",value:""},Ir=({variant:e,variants:n,updateVariant:a,removeVariant:o,apiPayload:s})=>{const[i,r]=f.useState(e.name),[l,u]=f.useState(e.weightType===X.FIX),[p,m]=f.useState(String(e.weight/10)),[g,S]=f.useState(e.payload||Er),[C,x]=gr(e.overrides||[]),{context:A}=ct(),[y,v]=f.useState({}),w=h=>{v(b=>({...b,[h]:void 0}))},R=(h,b)=>{v(E=>({...E,[h]:b}))};f.useEffect(()=>{var h;w("percentage"),(h=s.error)!=null&&h.includes("%")&&R("percentage","Total weight must equal 100%")},[s.error]);const P=!e.new,D=n.filter(({id:h,weightType:b})=>h!==e.id&&b===X.VARIABLE).length>0,$=h=>{const b=h.weightType===X.VARIABLE,E=n.some(L=>L.weightType===X.FIX),V=n.filter(L=>L.weightType===X.VARIABLE).length===1;return E&&V&&b},O=h=>{w("name"),Z(h,e.id)||R("name","A variant with that name already exists for this environment."),r(h)},B=h=>{(h===""||te(h))&&m(h)},U=h=>{T(h)||R("payload","Invalid JSON.")},Y=()=>{A.length>0&&x({type:"ADD",payload:{contextName:A[0].name,values:[]}})},K=h=>Boolean(h.length),Z=(h,b)=>P||!n.some(E=>E.name===h&&E.id!==b),te=h=>{if(!l)return!0;if(h===""||h.match(/\.[0-9]{2,}$/))return!1;const b=Number(h);return b>=0&&b<=100},T=h=>{try{return h.type==="json"&&JSON.parse(h.value),!0}catch{return!1}};return f.useEffect(()=>{a({...e,name:i,weight:Number(l?p:100)*10,weightType:l?X.FIX:X.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:g.value?g:void 0,overrides:C.map(h=>({contextName:h.contextName,values:h.values})).filter(h=>h.values&&h.values.length>0),isValid:K(i)&&Z(i,e.id)&&te(p)&&T(g)&&!s.error})},[i,l,p,g,C]),f.useEffect(()=>{l||m(String(e.weight/10))},[e.weight]),c(hr,{children:[t(mr,{arrow:!0,title:$(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t($e,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>o(e.id),disabled:$(e),children:t(tt,{})})})}),c(wr,{children:[c(vr,{children:[t(dn,{children:"Variant name"}),t(fr,{children:"This will be used to identify the variant in your code"}),t(Bt,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:Boolean(y.name),errorText:y.name,value:i,onChange:h=>O(h.target.value),disabled:P,required:!0})]}),t(I,{condition:D,show:c(br,{children:[t(yr,{label:"Custom percentage",control:t(sa,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:l,onChange:h=>u(h.target.checked)})}),t(Cr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(y.percentage),errorText:y.percentage,value:p,onChange:h=>B(h.target.value),required:l,disabled:!l,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(ra,{position:"end",children:"%"})}})]})})]}),c(Pt,{children:["Payload",t(Ye,{tooltip:"Passed along with the the variant object."})]}),c(un,{children:[t(Tr,{id:"variant-payload-type",name:"type",label:"Type",value:g.type,options:Ar,onChange:h=>{w("payload"),S(b=>({...b,type:h.target.value}))}}),t(Sr,{children:t(Bt,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:g.type!=="string",rows:g.type==="string"?1:4,value:g.value,onChange:h=>{w("payload"),S(b=>({...b,value:h.target.value}))},placeholder:g.type==="json"?'{ "hello": "world" }':"",onBlur:()=>U(g),error:Boolean(y.payload),errorText:y.payload})})]}),c(Pt,{children:["Overrides",t(Ye,{tooltip:"Here you can specify which users should get this variant."})]}),t(ur,{overrides:C,overridesDispatch:x}),t("div",{children:t(xr,{onClick:Y,variant:"text",color:"primary",children:"Add override"})})]})},Rr=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})),Fr=d(Qt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),kr=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})),$r=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Pr=d(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Br=d(he)(({theme:e})=>({marginTop:e.spacing(4)})),Dr=d("div")({display:"flex",flexDirection:"column"}),Or=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Dt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Vr=d(ye)(({theme:e})=>({margin:e.spacing(4,0)})),Mr=d(ia)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Lr=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),_r=d(re)(({theme:e})=>({marginLeft:e.spacing(3)})),jr=({environment:e,open:n,setOpen:a,getApiPayload:o,getCrPayload:s,onConfirm:i})=>{var xe;const r=F("projectId"),l=F("featureId"),{uiConfig:u}=lt(),{context:p}=ct(),{defaultStickiness:m}=ca(r),{isChangeRequestConfigured:g}=oe(r),{data:S}=ve(r),{changeRequestInReviewOrApproved:C,alert:x}=da(S),A=(e==null?void 0:e.variants)||[],[y,v]=f.useState([]),[w,R]=f.useState();f.useEffect(()=>{v(A.length?A.map(k=>({...k,isValid:!0,new:!1,id:_e()})):[{name:"",weightType:X.VARIABLE,weight:0,overrides:[],stickiness:(y==null?void 0:y.length)>0?y[0].stickiness:m,new:!0,isValid:!1,id:_e()}])},[n]);const P=(k,W)=>{v(ie=>mt(ie.map(Ae=>Ae.id===W?k:Ae),1e3))},D=()=>{const k=_e();v(W=>[...W,{name:"",weightType:X.VARIABLE,weight:0,overrides:[],stickiness:(W==null?void 0:W.length)>0?W[0].stickiness:"default",new:!0,isValid:!1,id:k}]),R(k)};f.useEffect(()=>{if(w){const k=document.getElementById(`variant-name-input-${w}`);k==null||k.scrollIntoView({behavior:"smooth",block:"center"}),k==null||k.focus({preventScroll:!0}),R(void 0)}},[w]);const $=y.map(({new:k,isValid:W,id:ie,...Ae})=>Ae),O=o(A,$),B=s($),U=async k=>{k.preventDefault(),i($)},Y=()=>T?`curl --location --request POST '${u.unleashUrl}/api/admin/projects/${r}/environments/${e==null?void 0:e.name}/change-requests' \\
|
|
2
|
-
--header 'Authorization: INSERT_API_KEY' \\
|
|
3
|
-
--header 'Content-Type: application/json' \\
|
|
4
|
-
--data-raw '${JSON.stringify(B,void 0,2)}'`:`curl --location --request PATCH '${u.unleashUrl}/api/admin/projects/${r}/features/${l}/environments/${e==null?void 0:e.name}/variants' \\
|
|
5
|
-
--header 'Authorization: INSERT_API_KEY' \\
|
|
6
|
-
--header 'Content-Type: application/json' \\
|
|
7
|
-
--data-raw '${JSON.stringify(O.patch,void 0,2)}'`,K=y.every(({isValid:k})=>k),Z=C((e==null?void 0:e.name)||""),te=Z?"Add to existing change request":"Add change to draft",T=g((e==null?void 0:e.name)||"")&&u.flags.crOnVariants,h=((xe=$[0])==null?void 0:xe.stickiness)||m,b=f.useMemo(()=>["default",...p.filter(k=>k.stickiness).map(k=>k.name)],[p]),E=b.map(k=>({key:k,label:k}));b.includes(h)||E.push({key:h,label:h});const V=async k=>{v(W=>W.map(ie=>({...ie,stickiness:k})))},L=k=>{V(k).catch(console.warn)},[_,q]=f.useState();return f.useEffect(()=>{q(void 0),O.error&&q(O.error)},[O.error]),t(Ke,{open:n,onClose:()=>{a(!1)},label:"",children:c(la,{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:Y,loading:!n,children:[c(Rr,{children:[c("div",{children:[t(Fr,{deprecated:!(e!=null&&e.enabled)}),t(kr,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ae,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:D,variant:"outlined",permission:ce,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c($r,{onSubmit:U,children:[t(I,{condition:Z,show:x,elseShow:t(I,{condition:Boolean(T),show:c(Pr,{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(Dr,{children:y.map(k=>t(Ir,{variant:k,variants:y,updateVariant:W=>P(W,k.id),removeVariant:()=>v(W=>mt(W.filter(ie=>ie.id!==k.id),1e3)),projectId:r,apiPayload:O},k.id))}),t(ae,{onClick:D,variant:"outlined",permission:ce,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(Vr,{}),t(I,{condition:y.length>0,show:c(M,{children:[t(Or,{children:t("p",{children:"Stickiness"})}),c(Dt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(it,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Mr,{value:h,label:"",editable:!0,onChange:k=>L(k.target.value)})})]}),elseShow:t(Dt,{children:"This environment has no variants. Get started by adding a variant."})}),c(Br,{severity:"error",hidden:!Boolean(_),children:[t("strong",{children:"Error: "}),_]}),c(Lr,{children:[t(re,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!K,children:T?te:"Save variants"}),t(_r,{onClick:()=>{a(!1)},children:"Cancel"})]})]})]})})},Nr=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)}})),zr=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Wr=d(Qt,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Ur=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})),qr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Hr=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),Gr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Yr=({environment:e,searchValue:n,children:a})=>{var i;const o=e.variants??[],s=((i=o[0])==null?void 0:i.stickiness)||"default";return c(Nr,{children:[c(zr,{children:[c("div",{children:[t(Wr,{deprecated:!e.enabled}),t(Ur,{deprecated:!e.enabled,children:e.name})]}),a]}),t(I,{condition:o.length>0,show:c(M,{children:[t(Hr,{children:t(ua,{variants:o,searchValue:n})}),t(I,{condition:o.length>1,show:c(M,{children:[c(Gr,{children:[t("p",{children:"Stickiness:"}),t(fe,{children:s})]}),c(qr,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(it,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},Kr=d(at)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Jr=({environment:e,permission:n,projectId:a,environmentId:o,onCopyVariantsFrom:s,otherEnvsWithVariants:i})=>{const[r,l]=f.useState(null),u=Boolean(r),p=e.variants??[];return t(I,{condition:i.length>0&&p.length===0,show:c(M,{children:[t(ae,{onClick:m=>{l(m.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":u?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:o,children:"Copy variants from"}),t(Pe,{anchorEl:r,open:u,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(m=>t(Be,{onClick:()=>s(m,e),children:t(Kr,{children:`Copy from ${m.name}`})},m.name))})]})})},Xr=({permission:e,projectId:n,environment:a,checked:o,onClick:s,...i})=>{const r=pa(e,n,a);return c(Be,{disabled:!r,onClick:s,...i,children:[t(ga,{checked:o}),a]})},Qr=d(Pe)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),Zr=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),ei=d(re)(({theme:e})=>({marginTop:e.spacing(2)})),ti=({current:e,environments:n,permission:a,projectId:o,onSubmit:s})=>{var A;const[i,r]=f.useState(null),l=Boolean(i),[u,p]=f.useState([]),m=y=>{p(v=>[...v,y])},g=y=>{p(v=>v.filter(({name:w})=>w!==y.name))},S=y=>{u.includes(y)?g(y):m(y)},C=()=>{p([]),r(null)},x=((A=n.find(y=>y.name===e))==null?void 0:A.variants)??[];return t(I,{condition:x.length>0&&n.length>1,show:c(M,{children:[t(re,{onClick:y=>{r(y.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",children:"Push to environment"}),c(Qr,{anchorEl:i,open:l,onClose:()=>r(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(Xr,{projectId:o,permission:a,environment:y.name,checked:u.includes(y),onClick:()=>S(y)},y.name)),c(Zr,{children:[t(ye,{}),c(ei,{variant:"outlined",onClick:()=>{s(u),C()},disabled:u.length===0,children:["Push to selected (",u.length,")"]})]})]})]})})},ni=d(he)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),ai=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),oi=()=>{const{uiConfig:e}=lt(),{setToastData:n,setToastApiError:a}=G(),o=et(),s=De(o.breakpoints.down("md")),i=F("projectId"),r=F("featureId"),{feature:l,refetchFeature:u,loading:p}=j(i,r),{patchFeatureEnvironmentVariants:m,overrideVariantsInEnvironments:g}=Te(),{refetch:S}=ve(i),{addChange:C}=nt(),{isChangeRequestConfigured:x}=oe(i),[A,y]=f.useState(""),[v,w]=f.useState(),[R,P]=f.useState(!1),D=f.useMemo(()=>{var T;return((T=l==null?void 0:l.environments)==null?void 0:T.map(h=>({...h,crEnabled:e.flags.crOnVariants&&x(h.name)})))||[]},[l.environments,e.flags.crOnVariants]),$=(T,h)=>fa(T,h),O=(T,h)=>{try{const b=ma(h,1e3);return{patch:$(T,b)}}catch(b){return{patch:[],error:z(b)}}},B=T=>({feature:r,action:"patchVariant",payload:{variants:T}}),U=async(T,h)=>{if(T.crEnabled)await C(i,T.name,B(h)),S();else{const b=T.variants??[],{patch:E,error:V}=O(b,h);if(E.length===0)return;if(V){n({type:"error",title:V});return}await m(i,r,T.name,E)}u()},Y=async(T,h)=>{try{const b=h.filter(({crEnabled:q})=>q),E=h.filter(({crEnabled:q})=>!q);b.length&&await Promise.all(b.map(q=>C(i,q.name,B(T)))),E.length&&await g(i,r,T,E.map(({name:q})=>q)),S(),u();const V=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",L=b.length?`Variants push added to ${b.length===1?`${b[0].name} draft`:`${b.length} drafts`}`:"",_=`${V}${V&&L?". ":""}${L}`;n({title:_,type:"success"})}catch(b){a(z(b))}},K=T=>{w(T),P(!0)},Z=async T=>{if(v)try{await U(v,T),P(!1),n({title:v.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(h){a(z(h))}},te=async(T,h)=>{try{const b=T.variants??[];await U(h,b),n({title:h.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(b){a(z(b))}};return c(dt,{isLoading:p,header:t(ha,{title:"Variants",actions:t(I,{condition:!s,show:t(M,{children:t(ft,{initialValue:A,onChange:y})})}),children:t(I,{condition:s,show:t(ft,{initialValue:A,onChange:y})})}),children:[c(ni,{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."]}),D.map(T=>{var b;const h=D.filter(({name:E,variants:V})=>E!==T.name&&(V==null?void 0:V.length));return t(Yr,{environment:T,searchValue:A,children:c(ai,{children:[t(ti,{current:T.name,environments:D,permission:ce,projectId:i,onSubmit:E=>Y(T.variants??[],E)}),t(Jr,{environment:T,permission:ce,projectId:i,environmentId:T.name,onCopyVariantsFrom:te,otherEnvsWithVariants:h}),t(I,{condition:Boolean((b=T.variants)==null?void 0:b.length),show:t(Q,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>K(T),permission:ce,projectId:i,environmentId:T.name,tooltipProps:{title:"Edit variants"},children:t(me,{})}),elseShow:t(ae,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>K(T),variant:"outlined",permission:ce,projectId:i,environmentId:T.name,children:"Add variant"})})]})},T.name)}),t(jr,{environment:v,open:R,setOpen:P,getApiPayload:O,getCrPayload:B,onConfirm:Z})]})},si=be("api/admin/client-metrics/features"),pn=(e,n)=>{const a=be(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:o,error:s}=Qe(a,()=>ri(a)),i=f.useCallback(()=>{Ze(si).catch(console.warn)},[]);return{featureMetrics:o==null?void 0:o.data,loading:!s&&!o,refetchFeatureMetrics:i,error:s}},ri=e=>fetch(e).then(ke("Features")).then(n=>n.json()).then(),Se=48,ii=({hoursBack:e,setHoursBack:n})=>{const a=o=>{n(ci(o))};return t(ya,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:li,value:String(e),onChange:a,fullWidth:!0})},ci=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Se}},li=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Se}`,label:`Last ${Se} hours`}],di=({metrics:e,tableSectionId:n})=>{const a=De(Zt.breakpoints.down("md")),o=f.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:s,getTableBodyProps:i,headerGroups:r,rows:l,prepareRow:u,setHiddenColumns:p}=Le.useTable({initialState:o,columns:Ot,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Sa}},Le.useGlobalFilter,Le.useSortBy);return ba([{condition:a,columns:["appName","environment"]}],p,Ot),e.length===0?null:c(Ca,{...s(),rowHeight:"standard",id:n,children:[t(va,{headerGroups:r}),t(wa,{...i(),children:l.map(m=>(u(m),t(Ta,{hover:!0,...m.getRowProps(),children:m.cells.map(g=>t(xa,{...g.getCellProps(),children:g.render("Cell")}))})))})]})},Ot=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Aa,{icon:t(ho,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Ea,{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"}],ui=({metrics:e,...n})=>{const a=f.useMemo(()=>e.reduce((s,i)=>s+i.yes,0),[e]),o=f.useMemo(()=>e.reduce((s,i)=>s+i.no,0),[e]);return t(rn,{...n,totalYes:a,totalNo:o})},pi=({metrics:e,hoursBack:n})=>{const a=yt(),o=yt();return e.length===0?c(H,{mt:6,children:[t(N,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(N,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):c(f.Suspense,{fallback:null,children:[t(H,{borderTop:1,pt:2,mt:3,borderColor:Zt.palette.divider,children:t(gi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(H,{mt:4,children:t(ui,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:o})}),t(H,{mt:4,children:t(di,{metrics:e,tableSectionId:o})})]})},gi=Ia.lazy(()=>import("./FeatureMetricsChart-37e55387.js")),Xe=e=>{const{search:n}=window.location,a=ge(),o=f.useMemo(()=>new URLSearchParams(n),[n]),s=f.useCallback(i=>{const r=new URLSearchParams(n);r.set(e,i),a({search:r.toString()},{replace:!0})},[e,n,a]);return[o.get(e)||void 0,s]},hi=e=>{const[n,a]=Xe(e),o=f.useCallback(s=>a(String(s)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,o]},mi=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),fi=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),yi=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}})),Vt=({title:e,values:n,value:a,setValue:o})=>{const s=r=>()=>{n.has(r)&&o(r)},i=f.useMemo(()=>Array.from(n).sort((r,l)=>r.localeCompare(l)),[n]);return c("div",{children:[t(mi,{children:e}),t(fi,{children:i.map(r=>t(yi,{children:t(Ht,{label:r,onClick:s(r),"aria-pressed":r===a,sx:Ra})},r))})]})},Si=d("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),bi=()=>{const e=F("projectId"),n=F("featureId"),a=Ci(e,n),o=vi(n);Gt("Metrics");const[s=Se,i]=hi("hoursBack"),{featureMetrics:r}=pn(n,s),[l,u]=f.useState(r);f.useEffect(()=>{r&&u(r)},[r]);const p=Array.from(a)[0],m=Array.from(o)[0],[g=p,S]=Xe("environment"),[C=m,x]=Xe("application"),A=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===g).filter(y=>y.appName===C),[l,g,C]);return A?c(dt,{children:[c(ne,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(ne,{item:!0,xs:12,md:5,children:t(I,{condition:a.size>0,show:t(Vt,{title:"Environments",values:a,value:g,setValue:S})})}),t(ne,{item:!0,xs:12,md:5,children:t(I,{condition:o.size>0,show:t(Vt,{title:"Applications",values:o,value:C,setValue:x})})}),t(ne,{item:!0,xs:12,md:2,children:t(Si,{children:t(ii,{hoursBack:s,setHoursBack:i})})})]}),t(pi,{metrics:A,hoursBack:s})]}):null},Ci=(e,n)=>{const{feature:a}=j(e,n),o=a.environments.map(s=>s.name);return new Set(o)},vi=e=>{const{featureMetrics:n=[]}=pn(e,Se),a=n.map(o=>o.appName);return new Set(a)},wi=(e,n)=>{const a=new Set(e),o=new Set(n);return a.size!==o.size?!1:[...a].every(s=>o.has(s))},Mt=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Lt=d(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Ti=d(rt)({padding:0}),xi=({projectId:e,open:n,onClose:a,onClick:o,feature:s,changeRequests:i})=>{const r=F("projectId"),{project:l}=en(e),{isChangeRequestConfiguredInAnyEnv:u}=oe(e),p=u(),m=f.useMemo(()=>wi(s.environments.map(S=>S.name),l.environments),[s,l]),g=i?i.length>0:!1;return t(I,{condition:m&&!g&&!p,show:t(de,{open:n,onClose:a,onClick:o,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(Mt,{children:[t(Lt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(de,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:c(Mt,{children:[t(Lt,{severity:"warning",children:"Cannot proceed with the move"}),t(I,{condition:!m,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(I,{condition:g,show:c(M,{children:[t("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t(Ti,{children:i==null?void 0:i.map(S=>t(Re,{children:c(J,{to:`/projects/${r}/change-requests/${S.id}`,children:["View change request"," ",S.id]})},S.id))})]})}),t(I,{condition:p,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(J,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Ai=e=>fetch(e).then(ke("ChangeRequest")).then(n=>n.json()),Ei=(e,n)=>{const{data:a,error:o,mutate:s}=Fa([],be(`api/admin/projects/${e}/change-requests/pending/${n}`),Ai);return{changeRequests:a,loading:!o&&!a,refetch:s,error:o}},Ii=()=>{const{hasAccess:e}=f.useContext(ot),n=F("projectId"),a=F("featureId"),{feature:o,refetchFeature:s}=j(n,a),[i,r]=f.useState(!1),{changeFeatureProject:l}=Te(),{setToastData:u,setToastApiError:p}=G(),[m,g]=f.useState(n),{projects:S}=ka(),C=ge(),{changeRequests:x}=Ei(n,a),A=async()=>{try{m&&(await l(n,a,m),s(),u({title:"Project changed",type:"success"}),r(!1),C(`/projects/${m}/features/${a}/settings`,{replace:!0}))}catch(v){p(z(v))}},y=f.useMemo(()=>S.map(v=>v.id).filter(v=>e(St,v)),[S,e]);return y.length===0?null:c(M,{children:[t($a,{value:m,onChange:g,label:"Project",filter:v=>y.includes(v),enabled:!0}),t(ae,{permission:St,onClick:()=>r(!0),disabled:m===n,projectId:n,children:"Save"}),t(xi,{changeRequests:x,projectId:m,open:i,feature:o,onClose:()=>r(!1),onClick:A})]})},Ri=d("div")({display:"flex",alignItems:"center"}),Fi=d(N)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),ki=({projectId:e,featureId:n})=>{var i;const{feature:a}=j(e,n),o=ge();return c(M,{children:[c(Ri,{children:[t(Fi,{children:"Feature information"}),t(Q,{permission:le,projectId:e,"data-loading":!0,onClick:()=>{o(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(me,{})})]}),c(N,{children:["Name: ",t("strong",{children:a.name})]}),c(N,{children:["Description:"," ",t("strong",{children:(i=a.description)!=null&&i.length?a.description:"no description"})]}),c(N,{children:["Type: ",t("strong",{children:a.type})]}),c(N,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Ee="metadata",Ge="project",$i=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Pi=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),Bi=()=>{const e=F("projectId"),n=F("featureId"),[a,o]=f.useState(Ee),{uiConfig:s}=lt();return t(dt,{header:"Settings",sx:{padding:0},children:c(H,{sx:{display:"flex"},children:[t($i,{children:c(rt,{children:[t(Re,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(Ee),selected:a===Ee,children:"Metadata"},0),t(Re,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>o(Ge),selected:a===Ge,hidden:!s.flags.P,children:"Project"},1)]})}),c(Pi,{children:[t(I,{condition:a===Ee,show:t(ki,{projectId:e,featureId:n})}),t(I,{condition:a===Ge&&s.flags.P,show:t(Ii,{})})]})]})})},Di=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(fe,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),_t=d("strong")({wordBreak:"break-all"}),Oi=()=>{const e=F("projectId"),n=F("featureId"),{archivedFeatures:a}=Pa(),o=Ba(e,{name:n});return a?a.some(i=>i.name===n)?c("p",{children:["The feature ",t(_t,{children:n})," has been archived. You can find it on the"," ",t(J,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(_t,{children:n})," does not exist. Would you like to"," ",t(J,{to:o,children:"create it"}),"?"]}):null},Vi=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Mi=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Li=d("div")({display:"flex",alignItems:"center"}),_i=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),ji=d("div")({flexShrink:0,display:"flex"}),Ni=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),zi=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Wi=d(Da)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Ki=()=>{const e=F("projectId"),n=F("featureId"),{refetch:a}=en(e),{favorite:o,unfavorite:s}=Oa(),{refetchFeature:i}=j(e,n),[r,l]=f.useState(!1),[u,p]=f.useState(!1),[m,g]=f.useState(!1),S=De(`(max-width:${500}px)`),{feature:C,loading:x,error:A,status:y}=j(e,n),v=ge(),{pathname:w}=Va(),R=Ma(x),P=`/projects/${e}/features/${n}`,D=[{title:"Overview",path:`${P}`,name:"overview"},{title:"Metrics",path:`${P}/metrics`,name:"Metrics"},{title:"Variants",path:`${P}/variants`,name:"Variants"},{title:"Settings",path:`${P}/settings`,name:"Settings"},{title:"Event log",path:`${P}/logs`,name:"Event log"}],$=D.find(B=>B.path===w)??D[0],O=async()=>{C!=null&&C.favorite?await s(e,C.name):await o(e,C.name),i()};return y===404?t(Oi,{}):A!==void 0?t("div",{ref:R}):c("div",{ref:R,children:[c(Vi,{children:[c(Mi,{children:[c(Li,{children:[t(La,{onClick:O,isFavorite:C==null?void 0:C.favorite}),c(_i,{"data-loading":!0,children:[C.name," "]}),t(I,{condition:!S,show:t(Di,{stale:C==null?void 0:C.stale})})]}),c(ji,{children:[t(Q,{permission:_a,projectId:e,"data-loading":!0,component:J,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(ja,{})}),t(Q,{permission:Na,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(to,{})}),t(Q,{onClick:()=>g(!0),permission:le,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(no,{})}),t(Q,{onClick:()=>l(!0),permission:le,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(za,{})})]})]}),t(Ni,{}),t(zi,{children:t(Wa,{value:$.path,indicatorColor:"primary",textColor:"primary",children:D.map(B=>t(Wi,{label:B.title,value:B.path,onClick:()=>v(B.path)},B.title))})})]}),c(Yt,{children:[t(se,{path:"metrics",element:t(bi,{})}),t(se,{path:"logs",element:t(yo,{})}),t(se,{path:"variants",element:t(oi,{})}),t(se,{path:"settings",element:t(Bi,{})}),t(se,{path:"*",element:t(or,{})})]}),t(ao,{isOpen:u,onConfirm:()=>{a(),v(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureIds:[n]}),t(oo,{isStale:C.stale,isOpen:m,onClose:()=>{g(!1),i()},featureId:n,projectId:e}),t(ln,{open:r,setOpen:l})]})};export{Ki as default};
|