unleash-server 4.22.2 → 4.22.3
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/db/project-store.js +2 -1
- package/dist/lib/db/project-store.js.map +1 -1
- package/dist/lib/services/project-service.js +1 -1
- package/dist/lib/services/project-service.js.map +1 -1
- package/dist/lib/types/model.d.ts +1 -1
- package/dist/test/e2e/api/admin/project/features.e2e.test.js +6 -1
- package/dist/test/e2e/api/admin/project/features.e2e.test.js.map +1 -1
- package/dist/test/e2e/api/proxy/proxy.e2e.test.js +1 -1
- package/dist/test/e2e/api/proxy/proxy.e2e.test.js.map +1 -1
- package/dist/test/e2e/services/api-token-service.e2e.test.js +1 -0
- package/dist/test/e2e/services/api-token-service.e2e.test.js.map +1 -1
- package/dist/test/e2e/services/project-service.e2e.test.js +44 -0
- package/dist/test/e2e/services/project-service.e2e.test.js.map +1 -1
- package/dist/test/fixtures/fake-project-store.js +1 -0
- package/dist/test/fixtures/fake-project-store.js.map +1 -1
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/{CreateProject-51932050.js → CreateProject-a2c9a780.js} +1 -1
- package/frontend/build/static/{Error-e6e1194a.js → Error-38b8cdc0.js} +1 -1
- package/frontend/build/static/{ExpandMore-d71bbced.js → ExpandMore-ee840700.js} +1 -1
- package/frontend/build/static/{FeatureArchiveDialog-fd71aac2.js → FeatureArchiveDialog-0d7ae6c3.js} +1 -1
- package/frontend/build/static/{FeatureMetricsChart-66e2ebdf.js → FeatureMetricsChart-ed667dfd.js} +1 -1
- package/frontend/build/static/FeatureViewLazyExport-1b33033a.js +7 -0
- package/frontend/build/static/{LazyAdminExport-17ef1739.js → LazyAdminExport-f1db04ed.js} +2 -2
- package/frontend/build/static/{LazyProjectExport-96365c31.js → LazyProjectExport-984413bf.js} +1 -1
- package/frontend/build/static/{NetworkOverview-02d7cec9.js → NetworkOverview-c9972cf4.js} +1 -1
- package/frontend/build/static/{NetworkTraffic-ea8ea762.js → NetworkTraffic-b4d65658.js} +1 -1
- package/frontend/build/static/{Playground-1b14c01c.js → Playground-82d86aa7.js} +1 -1
- package/frontend/build/static/{StrategyItemContainer-7ce39bda.js → StrategyItemContainer-72e360fd.js} +1 -1
- package/frontend/build/static/{chartjs-adapter-date-fns.esm-8ccfeb24.js → chartjs-adapter-date-fns.esm-00d0c032.js} +1 -1
- package/frontend/build/static/{index-17782336.js → index-78310b22.js} +1 -1
- package/frontend/build/static/{index-1d165488.js → index-99d4171f.js} +61 -61
- package/frontend/build/static/{index-96dcc77e.js → index-c65a88d1.js} +1 -1
- package/frontend/build/static/{unknownify-132fbce3.js → unknownify-9d8df72f.js} +1 -1
- package/frontend/build/static/{useProjectRole-f048973d.js → useProjectRole-dba93dda.js} +1 -1
- package/package.json +1 -1
- package/frontend/build/static/FeatureViewLazyExport-3403c2b4.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-99d4171f.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-99d4171f.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-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};
|
|
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-99d4171f.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 mn,aC as fn,s as d,r as f,aD as yn,aE as Sn,aF as ht,j as t,aG as bn,aH as Cn,c as zt,aI as F,aJ as j,aK as vn,f as c,aL as wn,C as I,aM as Q,aN as le,aO as J,aP as me,aQ as Tn,aR as Qe,aS as be,aT as ke,aU as Ze,u as et,aV as oe,F as M,aW as mt,aX as ft,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 Wt,a4 as z,b3 as xn,b4 as An,b5 as En,b6 as In,ap as we,b7 as Rn,b8 as ue,b9 as ee,m as $e,ba as Fn,bb as kn,bc as Pe,a8 as Be,bd as Ut,be as qt,bf as at,bg as $n,bh as Pn,bi as Bn,a as H,p as Dn,N as De,B as fe,bj as ot,a9 as re,bk as On,x as st,an as Ie,E as Vn,bl as rt,bm as Re,P as Mn,bn as Ln,bo as ne,bp as _n,bq as jn,D as Nn,br as zn,bs as Wn,bt as Un,bu as Ht,bv as qn,bw as Hn,bx as Gn,by as Yn,bz as Kn,bA as Jn,bB as Te,bC as Xn,bD as Qn,bE as it,bF as Zn,bG as ea,as as Gt,bH as ta,w as Yt,af as ye,bI as na,bJ as aa,bK as Ye,bL as Kt,bM as Jt,bN as se,bO as Ke,bP as oa,ac as Xt,bQ as Qt,a3 as ct,ad as sa,bR as ra,bS as Zt,bT as ia,bU as ca,bV as en,bW as la,H as lt,bX as da,am as ua,av as pa,bY as ce,bZ as yt,b_ as ga,b$ as ha,c0 as ma,c1 as fa,ak as dt,al as ya,V as St,c2 as Sa,c3 as ba,c4 as Ca,c5 as tn,d as Le,l as va,U as wa,g as Ta,S as xa,h as Aa,i as Ea,k as Ia,I as Ra,c6 as Fa,c7 as ka,c8 as bt,c9 as $a,ca as nn,cb as Pa,ae as Ba,cc as Ct,cd as Da,ce as Oa,cf as Va,cg as Ma,ch as La,ci as _a,M as ja,cj as Na,ck as za,cl as Wa,cm as Ua,cn as qa,co as Ha}from"./index-1d165488.js";import{C as Oe,f as Ga,u as Ya,U as Ka,E as Ja,V as Xa,a as Qa,b as Za,c as eo,T as to,d as no,F as ao,A as oo,W as so,e as ro,g as io}from"./FeatureArchiveDialog-fd71aac2.js";import{S as co}from"./StrategyItemContainer-7ce39bda.js";import{E as lo}from"./ExpandMore-d71bbced.js";import{v as _e}from"./v4-a960c1f4.js";function uo(e){return mn("MuiCardContent",e)}fn("MuiCardContent",["root"]);const po=["className","component"],go=e=>{const{classes:n}=e;return Cn({root:["root"]},uo,n)},ho=d("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),mo=f.forwardRef(function(n,a){const o=yn({props:n,name:"MuiCardContent"}),{className:s,component:i="div"}=o,r=Sn(o,po),l=ht({},o,{component:i}),u=go(l);return t(ho,ht({as:i,className:bn(u.root,s),ownerState:l,ref:a},r))}),fo=mo,yo=zt(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"),So=zt(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"),bo=d("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Co=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=j(e,n);return a.name?t(bo,{children:t(vn,{title:"Event log",feature:n,displayInline:!0})}):null},vo=d("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.primary.contrastText,backgroundColor:e.palette.background.alternative,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),wo=d("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),To=d("div")({display:"flex",alignItems:"center"}),xo=d("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),Ao=d("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),vt=d("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),wt=d("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),Eo=()=>{const e=F("projectId"),n=F("featureId"),{feature:a}=j(e,n),{project:o,description:s,type:i}=a,r=Tn(i);return t(vo,{children:c(wo,{children:[c(To,{"data-loading":!0,children:[t(r,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",c(xo,{children:[wn(i||"")," toggle"]})]}),c(Ao,{children:[c(vt,{"data-loading":!0,children:["Project: ",o]}),t(I,{condition:Boolean(s),show:c(vt,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(wt,{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(wt,{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})})})]})})})]})]})})},Tt={lastHourUsage:[],seenApplications:[]},Io=(e,n,a={})=>{const o=async()=>{const h=be(`api/admin/client-metrics/features/${n}`),g=await fetch(h,{method:"GET"}).then(ke("feature metrics"));return g.ok?g.json():Tt},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||Tt,error:r,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:s}},Ro=e=>({yes:0,no:0,environment:e,timestamp:""}),Fo=(e,n)=>e.map(a=>n.lastHourUsage.find(s=>s.environment===a.name)||Ro(a.name)),ko=({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(So,{style:i,titleAccess:o})})},an=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),$o=({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(an,{})}),Po=d("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Bo=({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(an,{}),t(Po,{children:t(N,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(N,{fontWeight:"bold",children:"Remove strategy"})]}),Do=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{deleteStrategyFromFeature:s}=Ce(),{setToastData:i,setToastApiError:r}=G(),l=ge(),{refetchFeature:u}=j(e,n);return async h=>{try{h.preventDefault(),await s(e,n,a,o),i({title:"Strategy deleted",type:"success"}),u(),l(Wt(e,n))}catch(g){r(z(g))}}},Oo=({projectId:e,featureId:n,environmentId:a,strategyId:o})=>{const{addChange:s}=nt(),{refetch:i}=ve(e),{setToastData:r,setToastApiError:l}=G();return async p=>{try{p.preventDefault(),await s(e,a,{action:"deleteStrategy",feature:n,payload:{id:o}}),r({title:"Changes added to the draft!",type:"success"}),await i()}catch(h){l(z(h))}}},Vo=({projectId:e,featureId:n,environmentId:a,strategyId:o,disabled:s,icon:i})=>{const[r,l]=f.useState(!1),{isChangeRequestConfigured:u}=oe(e),p=Do({featureId:n,projectId:e,strategyId:o,environmentId:a}),h=Oo({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:mt,"data-testid":ft,tooltipProps:{title:"Remove strategy"},type:"button",children:t(tt,{})}),elseShow:t(ae,{onClick:()=>l(!0),projectId:e,environmentId:a,disabled:s,permission:mt,"data-testid":ft,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(I,{condition:u(a),show:t(Bo,{isOpen:r,onClose:()=>l(!1),onRemove:async g=>{await h(g),l(!1)}}),elseShow:t($o,{isOpen:r,onClose:()=>l(!1),onRemove:p})})]})},Mo=e=>(n,a,o)=>(o.revalidateOnFocus=!1,o.revalidateIfStale=!1,o.revalidateOnReconnect=!1,e(n,a,o));var Lo=xn(Qe,Mo);const on=(e,n)=>{const{refetchFeature:a}=j(e,n),o=An(e,n),{data:s,error:i,mutate:r}=Lo(["useFeatureImmutable",o],()=>En(o)),l=f.useCallback(async()=>{await r(),await a()},[r,a]);return{feature:(s==null?void 0:s.body)||In,refetchFeature:l,loading:!i&&!s,status:s==null?void 0:s.status,error:i}},ut=(e,n,a)=>{const{setToastData:o,setToastApiError:s}=G(),{addChange:i}=nt(),{refetch:r}=ve(e),[l,u]=f.useState({isOpen:!1}),p=f.useCallback((T,R,y)=>{u({featureName:n,environment:T,fromEnvironment:y,strategy:R,isOpen:!0})},[]),h=f.useCallback((T,R,y)=>{u({featureName:n,environment:T,fromEnvironment:y,strategies:R,isOpen:!0})},[]),g=f.useCallback(()=>{u({isOpen:!1})},[]),b=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),r(),u({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(T){s(z(T)),u({isOpen:!1})}},[i]),v=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(T=>i(e,l.environment,{feature:l.featureName,action:a,payload:T}))),r(),u({isOpen:!1}),o({type:"success",title:"Changes added to the draft!"})}catch(T){s(z(T)),u({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:h,onChangeRequestAddStrategyClose:g,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:v,changeRequestDialogDetails:l}},_o=({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]}),jo=({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:h}=G(),{refetchFeature:g}=j(o,s),{refetchFeature:b}=on(o,s),v=()=>{r(null)},T=Rn(o),{isChangeRequestConfigured:R}=oe(o),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:C,onChangeRequestAddStrategy:w,onChangeRequestAddStrategyConfirm:E}=ut(o,s,"addStrategy"),B=async P=>{const{id:O,...$}={...a,targetEnvironment:P};if(R(P)){await w(P,{id:O,...$},e);return}try{await u(o,s,P,a),g(),b(),p({title:"Strategy created",text:`Successfully copied a strategy to ${P}`,type:"success"})}catch(U){h(z(U))}v()},D=n.some(P=>T(ue,P));return c("div",{children:[t(Oe,{isOpen:y.isOpen,onClose:C,environment:y==null?void 0:y.environment,onConfirm:E,messageComponent:t(_o,{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:P=>{r(P.currentTarget)},"data-testid":Fn,disabled:!D,children:t(kn,{})})})}),t(Pe,{id:"basic-menu",anchorEl:i,open:l,onClose:v,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(P=>{const O=T(ue,P);return t(ee,{title:O?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Be,{onClick:()=>B(P),disabled:!O,children:[t(I,{condition:!O,show:t(Ut,{children:t(qt,{fontSize:"small"})})}),c(at,{children:["Copy to ",P]})]})})},P)})})]})},No=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:o,otherEnvironments:s,orderNumber:i,headerChildren:r})=>{const l=F("projectId"),u=F("featureId"),p=$n(l,u,e,n.id);return t(co,{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(jo,{environmentId:e,environments:s,strategy:n})}),t(Q,{permission:Pn,environmentId:e,projectId:l,component:J,to:p,tooltipProps:{title:"Edit strategy"},children:t(me,{})}),t(Vo,{projectId:l,featureId:u,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(Bn,{strategy:n})})},zo=(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)},Wo=({strategy:e,index:n,environmentName:a,otherEnvironments:o,isDragging:s,onDragStartRef:i,onDragOver:r,onDragEnd:l})=>{const u=F("projectId"),p=F("featureId"),h=f.useRef(null),g=zo(u,p,a,e.id);return c(H,{ref:h,onDragOver:r(h,n),sx:{opacity:s?"0.5":"1"},children:[t(I,{condition:n>0,show:t(Dn,{text:"OR"})}),t(No,{strategy:e,environmentId:a,otherEnvironments:o,onDragStart:i(h,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(Uo,{change:g})})]},e.id)},Uo=({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"})})]})},qo=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}})),Ho=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})),sn=({children:e})=>t(qo,{children:t(Ho,{children:e})}),Go=({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 h=l(ue,o,p);return t(ee,{title:h?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Be,{onClick:()=>a(p),disabled:!h,children:[t(I,{condition:!h,show:t(Ut,{children:t(qt,{fontSize:"small"})})}),c(at,{children:["Copy from ",p]})]})})},p)})})]})},Yo=d("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Ko=({payload:e,fromEnvironment:n,environment:a})=>c(Yo,{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]})]}),Jo=({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})]}),Xo=d(On)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),xt=({title:e,children:n,featureId:a,projectId:o,environmentId:s,strategy:i,Icon:r,onAfterAddStrategy:l})=>{const{addStrategyToFeature:u}=Ce(),{setToastApiError:p}=G(),{isChangeRequestConfigured:h}=oe(o),{changeRequestDialogDetails:g,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:v,onChangeRequestAddStrategyClose:T}=ut(o,a,"addStrategy");return c(M,{children:[t(Xo,{variant:"outlined",children:c(fo,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(N,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(r,{color:"disabled",sx:{mr:1}})," ",e]}),t(N,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(H,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(ae,{permission:ue,projectId:o,environmentId:s,variant:"outlined",size:"small",onClick:async()=>{try{h(s)?b(s,i):(await u(o,a,s,i),l())}catch(y){p(z(y))}},children:"Use template"})})]})}),t(Oe,{isOpen:g.isOpen,onClose:T,environment:g==null?void 0:g.environment,onConfirm:v,messageComponent:t(Jo,{environment:s,payload:g.strategy})})]})},Qo=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}})),Zo=d("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),es=d(st)(({theme:e})=>({fontWeight:e.fontWeight.bold})),ts=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}})),ns=({projectId:e,featureId:n,environmentId:a,strategy:o})=>{const s=Ie(o.name),i=we(o.name),r=Ga(e,n,a,o.name);return c(ts,{to:r,children:[t(Qo,{children:t(s,{})}),c("div",{children:[t(es,{text:o.displayName||i,maxWidth:"200",maxLength:25}),t(Zo,{children:o.description})]})]})},as=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:o}=Vn(),s=f.useMemo(()=>o.filter(i=>!i.deprecated),[o]);return t(rt,{dense:!0,children:s.map(i=>t(Re,{children:t(ns,{projectId:e,featureId:n,environmentId:a,strategy:i})},i.name))})},Je=({label:e,projectId:n,featureId:a,environmentId:o,variant:s,matchWidth:i})=>{const[r,l]=f.useState(),u=Boolean(r),p=u?"FeatureStrategyMenuPopover":void 0,h=()=>{l(void 0)};return c("div",{onClick:b=>b.stopPropagation(),children:[t(ae,{permission:ue,projectId:n,environmentId:o,onClick:b=>{l(b.currentTarget)},"aria-labelledby":p,variant:s,sx:{minWidth:i?"282px":"auto"},children:e}),t(Mn,{id:p,open:u,anchorEl:r,onClose:h,onClick:h,children:t(as,{projectId:n,featureId:a,environmentId:o})})]})},os=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),ss=d("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),rs=d("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),is=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:o}=Ce(),{setToastData:s,setToastApiError:i}=G(),{refetchFeature:r}=j(e,n),{refetchFeature:l}=on(e,n),{feature:u}=j(e,n),p=u==null?void 0:u.environments.filter(w=>w.name!==a&&w.strategies&&w.strategies.length>0),{isChangeRequestConfigured:h}=oe(e),{changeRequestDialogDetails:g,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:v,onChangeRequestAddStrategyClose:T}=ut(e,n,"addStrategy"),R=(w=!1)=>{r(),l(),s({title:w?"Strategies created":"Strategy created",text:w?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async w=>{var B;const E=((B=p==null?void 0:p.find(D=>D.name===w))==null?void 0:B.strategies)||[];if(h(a)){await b(a,E,w);return}try{await Promise.all(E.map(D=>{const{id:P,...O}={...D,environment:a};return o(e,n,a,O)})),R(!0)}catch(D){i(z(D))}},C=p&&p.length>0;return c(M,{children:[t(Oe,{isOpen:g.isOpen,onClose:T,environment:g==null?void 0:g.environment,onConfirm:v,messageComponent:t(Ko,{fromEnvironment:g.fromEnvironment,payload:g.strategies})}),c(os,{children:[t(ss,{children:"You have not defined any strategies yet."}),c(rs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(J,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(H,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(Je,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:C}),t(I,{condition:C,show:t(Go,{environmentId:a,environments:p.map(w=>w.name),onClick:y})})]}),t(H,{sx:{width:"100%",mt:3},children:t(sn,{children:"Or use a strategy template"})}),c(H,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(xt,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:R,Icon:Ie("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(xt,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:R,Icon:Ie("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:u.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},cs=d("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ls=d("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ds=({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,h]=f.useState((e==null?void 0:e.strategies)||[]),[g,b]=f.useState(null);if(f.useEffect(()=>{h((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const v=async C=>{try{await i(o,s,e.name,C),u(),r({title:"Order of strategies updated",type:"success"})}catch(w){l(z(w))}},T=(C,w)=>E=>{var B;b({id:p[w].id,index:w,height:((B=C.current)==null?void 0:B.offsetHeight)||0}),C!=null&&C.current&&(E.dataTransfer.effectAllowed="move",E.dataTransfer.setData("text/html",C.current.outerHTML),E.dataTransfer.setDragImage(C.current,20,20))},R=C=>(w,E)=>B=>{if(g===null||w.current===null||g.index===E||C===g.id)return;const{top:D,bottom:P}=w.current.getBoundingClientRect(),O=B.clientY-D<g.height,$=P-B.clientY<g.height,U=g.index>E;if(O&&U||$&&!U){const Y=[...p],K=Y.splice(g.index,1)[0];Y.splice(E,0,K),h(Y),b({...g,index:E})}},y=()=>{b(null),v(p.map((C,w)=>({id:C.id,sortOrder:w})))};return t(cs,{children:c(ls,{children:[t(I,{condition:p.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(I,{condition:p.length>0,show:t(M,{children:p.map((C,w)=>t(Wo,{strategy:C,index:w,environmentName:e.name,otherEnvironments:a,isDragging:(g==null?void 0:g.id)===C.id,onDragStartRef:T,onDragOver:R(C.id),onDragEnd:y},C.id))}),elseShow:t(is,{projectId:o,featureId:s,environmentId:e.name})})]})})},rn=(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 us(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=us;function ps(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=ps;Object.defineProperty(Ve,"__esModule",{value:!0});Ve.millify=void 0;const je=Me,At=pe,Et=1e3;function*It(e){let n=Et;for(;;){const a=e/n;if(a<1)return;yield a,n*=Et}}function cn(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=At.parseValue(e)}catch(v){return v instanceof Error&&console.warn(`WARN: ${v.message} (millify)`),String(e)}const i=s<0?"-":"";s=Math.abs(s);let r=0;for(const v of It(s))s=v,r+=1;if(r>=o.units.length)return e.toString();let u=At.roundTo(s,o.precision);for(const v of It(u))u=v,r+=1;const p=(a=o.units[r])!==null&&a!==void 0?a:"",h=o.lowercase?p.toLowerCase():p,g=o.space?" ":"",b=u.toString().replace(je.defaultOptions.decimalSeparator,o.decimalSeparator);return`${i}${b}${g}${h}`}Ve.millify=cn;var gs=Ve.default=cn;const Fe=({value:e,threshold:n=1e6,precision:a=2})=>{let o,s=!1;e<n?o=e.toLocaleString():(o=gs(e,{precision:a}),s=!0);const i=t("span",{"data-testid":Ln,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})),ln=({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:[rn(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,"."]})]})})]})},hs=({environmentMetric:e})=>e?c(M,{children:[t(sn,{children:"Feature toggle exposure"}),t("div",{children:t(ln,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Rt=d("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Ft=d("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),kt=d("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),$t=d("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),ms=d(_n)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),fs=d("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),ys=({environmentMetric:e,disabled:n=!1})=>{const a=jn();if(!e)return null;const o=e.yes+e.no,s=rn(o,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Rt,{children:[c(Ft,{children:[c(kt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[s,"%"]}),c($t,{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(ms,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Rt,{children:[c(Ft,{children:[c(kt,{children:[s,"%"]}),c($t,{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(fs,{"data-loading":!0,children:t(Nn,{percentage:s,size:"3rem"})})]})},Ss=({strategyName:e})=>{const n=Ie(e);return t(ee,{title:we(e),arrow:!0,children:t(bs,{children:t(n,{})})})},bs=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)}})),Cs=({strategies:e})=>e!=null&&e.length?t(vs,{"aria-label":"Feature strategies",children:e.map(n=>t(ws,{children:t(Ss,{strategyName:n.name})},n.id))}):null,vs=d("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),ws=d("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Ts=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})),xs=d(zn)({boxShadow:"none",background:"none"}),As=d(Wn)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),Es=d(Un,{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)}})),Is=d(ds)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Rs=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})),Fs=d("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),ks=d(ko)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),$s=d(st)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Ps=d("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),Bs=({env:e})=>{var p;const n=F("projectId"),a=F("featureId"),{metrics:o}=Io(n,a),{feature:s}=j(n,a),{value:i}=Ht(),l=Fo(s==null?void 0:s.environments,o).find(h=>h.environment===e.name),u=s==null?void 0:s.environments.find(h=>h.name===e.name);return t(I,{condition:!Boolean(new Set(i.hiddenEnvironments).has(e.name)),show:t(Ts,{enabled:e.enabled,children:c(xs,{"data-testid":`${qn}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[c(As,{expandIcon:t(lo,{titleAccess:"Toggle"}),children:[c(Rs,{"data-loading":!0,enabled:e.enabled,children:[c(Fs,{children:[t(ks,{enabled:e.enabled}),t("div",{children:t($s,{text:e.name,maxWidth:"100",maxLength:15})}),t(I,{condition:!e.enabled,show:t(fe,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),c(Ps,{children:[t(Je,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(Cs,{strategies:u==null?void 0:u.strategies})]})]}),t(ys,{environmentMetric:l,disabled:!e.enabled})]}),c(Es,{enabled:e.enabled,children:[t(Is,{featureEnvironment:u,isDisabled:!e.enabled,otherEnvironments:s==null?void 0:s.environments.map(({name:h})=>h).filter(h=>h!==e.name)}),t(I,{condition:(((p=u==null?void 0:u.strategies)==null?void 0:p.length)||0)>0,show:c(M,{children:[t(H,{sx:{display:"flex",justifyContent:"center",py:1},children:t(Je,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(hs,{environmentMetric:l})]})})]})]})})})},Ds=()=>{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(Bs,{env:s},s.name))})},Os=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Vs=d("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Ms=({feature:e,header:n})=>{const{locationSettings:a}=Hn();return c(Os,{children:[n,c("div",{"data-loading":!0,children:[t(Vs,{children:"Created at:"}),t("span",{children:Gn(Yn(e.createdAt),a.locale)})]})]})},Ls=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}})),_s=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(Ls,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(I,{condition:n.has(e.name),show:t(Kn,{}),elseShow:t(Jn,{})})}),js=d("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),Ns=d("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),zs=({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:h,toggleFeatureEnvironmentOff:g}=Te(),{refetchFeature:b}=j(u,p),{setToastData:v,setToastApiError:T}=G(),{isChangeRequestConfigured:R}=oe(u),{onChangeRequestToggle:y,onChangeRequestToggleClose:C,onChangeRequestToggleConfirm:w,changeRequestDialogDetails:E}=Ya(u),B=async()=>{try{await h(u,p,r),v({type:"success",title:`Available in ${r}`,text:`${p} is now available in ${r} based on its defined strategies.`}),b(),n&&n()}catch($){$ instanceof Error&&$.message===Ja?a():T(z($))}},D=async()=>{try{await g(u,p,r),v({type:"success",title:`Unavailable in ${r}`,text:`${p} is unavailable in ${r} and its strategies will no longer have any effect.`}),b(),n&&n()}catch($){T(z($))}},P=async $=>{if(R(r)){$.preventDefault(),y(p,r,!l);return}if(l){await D();return}await B()},O=c(M,{children:[" ",c("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(st,{text:r,maxWidth:"120",maxLength:15})]});return c(js,{children:[c(Ns,{children:[t(Xn,{tooltip:l?`Disable feature in ${r}`:`Enable feature in ${r}`,permission:Qn,projectId:u,checked:l,onChange:P,environmentId:r}),o??O]}),t(_s,{environment:e,hiddenEnvironments:s,setHiddenEnvironments:i}),t(Oe,{isOpen:E.isOpen,onClose:C,environment:E==null?void 0:E.environment,onConfirm:w,messageComponent:t(Ka,{enabled:E==null?void 0:E.enabled,featureName:E==null?void 0:E.featureName,environment:E.environment})})]})},Ws=d("div")(({theme:e})=>({padding:e.spacing(3)})),Us=d("div")(()=>({display:"flex",flexDirection:"column"})),qs=d("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Hs=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Pt=d("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Gs=d(it)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),Ys=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:o})=>{const[s,i]=f.useState(!1),[r,l]=f.useState(""),u=e.environments.some(p=>{var h;return p.enabled&&((h=p.variants)==null?void 0:h.length)});return c(Ws,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const h=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,g=p.variants??[],b=g.length>0&&c(M,{children:[t(Pt,{}),t(ee,{title:"View variants",arrow:!0,describeChild:!0,children:t(Gs,{component:J,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:g.length===1?"1 variant":`${g.length} variants`})})]}),v=p.enabled&&g.length===0&&u;return t(zs,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:o,showInfoBox:()=>{l(p.name),i(!0)},children:c(Us,{children:[t(qs,{children:p.name}),c(Hs,{children:[h,b,t(I,{condition:v,show:c(M,{children:[t(Pt,{}),t(Xa,{})]})})]})]})},p.name)}),t(Qa,{open:s,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:r})]})},dn=(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}=Zn(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}},Ks=d("section")(({theme:e})=>({["& > *"]:{margin:e.spacing(1,0)}})),qe=e=>e.map(n=>({title:n.value})),Bt=(e,n)=>e.map(a=>({value:a.title,type:n})),un=({open:e,setOpen:n})=>{const{tagTypes:a}=ea(),o=F("featureId"),{createTag:s}=Za(),{updateFeatureTags:i,loading:r}=Te(),{tags:l,refetch:u,loading:p}=dn(o),{setToastData:h}=G(),[g,b]=f.useState({name:"simple",description:"Simple tag to get you started",icon:""}),v=r||p,[T,R]=f.useState(0),{trackEvent:y}=Gt(),[C,w]=f.useState(qe(l.filter(m=>m.type===g.name))),{tags:E,refetch:B}=eo(g.name),D=f.useMemo(()=>qe(E),[E]);f.useEffect(()=>{l&&g&&w(qe(l.filter(m=>m.type===g.name)))},[JSON.stringify(l),g]);const P=()=>{n(!1),w([])};function O(m,S){const A=m.filter(L=>L.type===g.name).filter(L=>!S.find(_=>L.value===_.value&&L.type===_.type)),V=S.filter(L=>L.type===g.name).filter(L=>!m.find(_=>L.value===_.value&&L.type===_.type));return R(A.length+V.length),{added:A,removed:V}}const $=m=>m.filter(S=>!S.title.startsWith("Create")),U=async(m,S)=>{try{await i(o,{addedTags:m,removedTags:S}),await u()}catch(A){const V=z(A);h({type:"error",title:"Failed to add tag",text:V,confetti:!1})}},Y=(m,S)=>{let A="We successfully";return m>0&&(A=A.concat(` added ${m} new tag${m>1?"s":""}`)),m>0&&S>0&&(A=A.concat(" and ")),S>0&&(A=A.concat(` removed ${S} tag${S>1?"s":""}`)),A},K=async m=>{m.preventDefault();const S=Bt($(C),g.name),{added:A,removed:V}=O(S,l);T>0&&(await U(A,V),T>1&&y("suggest_tags",{props:{eventType:"multiple_tags_added"}}),T>0&&h({type:"success",title:`Updated tag${A.length>1?"s":""} to toggle`,text:Y(A.length,V.length),confetti:!0})),R(0),w([]),n(!1)},te=(m,S)=>{S!=null&&typeof S!="string"&&(m.preventDefault(),b(S),w([]),R(0))},Z=(m,S,A)=>{const V=ta(S);A==="selectOption"&&S.forEach((_,q)=>{if(typeof _!="string"&&_.inputValue&&_.inputValue!==""){const xe={value:_.inputValue,type:g.name};s(xe).then(()=>{y("suggest_tags",{props:{eventType:"tag_created"}}),B()}),_.title=_.inputValue,_.inputValue="",V[q]=_}});const L=Bt($(V),g.name);O(L,l),w(V)},x="add-tag-form";return t(de,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:K,disabledPrimaryButton:v||T===0,onClose:P,formId:x,children:c(M,{children:[t(N,{paragraph:!0,sx:{marginBottom:m=>m.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:x,onSubmit:K,children:c(Ks,{children:[t(to,{options:a,value:g,onChange:te}),t(no,{options:D,existingTags:l,tagType:g,selectedOptions:C,onChange:Z})]})})]})})},Js=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Xs=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Qs=d(Yt)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Zs=d(ye)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),er=d(re)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),tr=({feature:e,header:n})=>{const{tags:a,refetch:o}=dn(e.name),{deleteTagFromFeature:s}=Te(),[i,r]=f.useState(!1),[l,u]=f.useState(!1),[p,h]=f.useState(),{setToastData:g,setToastApiError:b}=G(),{hasAccess:v}=f.useContext(ot),T=v(le,e.project),R=async()=>{if(p)try{await s(e.name,p.type,p.value),o(),g({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){b(z(y))}};return c(Js,{children:[n,t(Xs,{children:a.map(y=>{const C=`${y.type}:${y.value}`;return t(Qs,{label:C,deleteIcon:t(na,{titleAccess:"Remove"}),onDelete:T?()=>{u(!0),h(y)}:void 0},C)})}),t(I,{condition:T,show:c(M,{children:[t(I,{condition:a.length>0,show:t(Zs,{})}),t(er,{"data-loading":!0,variant:"outlined",startIcon:t(aa,{}),onClick:()=>r(!0),children:"Add new tag"})]})}),t(un,{open:i,setOpen:r}),c(de,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{u(!1),h(void 0)},onClick:()=>{u(!1),R(),h(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},nr=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}})),ar=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=F("projectId"),o=F("featureId"),{feature:s}=j(a,o);return c(nr,{children:[t(Ys,{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(Ms,{header:t(He,{"data-loading":!0,children:"Feature toggle details"}),feature:s}),t(ye,{}),t(tr,{header:t(He,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:s})]})},or=()=>{const{trackEvent:e}=Gt(),{value:n,setValue:a}=Ht(),[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}})}}},sr=d("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),rr=d("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),ir=()=>{const e=ge(),n=F("projectId"),a=F("featureId"),o=Wt(n,a),{hiddenEnvironments:s,setHiddenEnvironments:i}=or(),r=()=>e(o);return Kt(a),c(sr,{children:[c("div",{children:[t(Eo,{}),t(ar,{hiddenEnvironments:s,setHiddenEnvironments:i})]}),t(rr,{children:t(Ds,{})}),c(Jt,{children:[t(se,{path:"strategies/create",element:t(Ke,{label:"Create feature strategy",onClose:r,open:!0,children:t(ao,{})})}),t(se,{path:"strategies/edit",element:t(Ke,{label:"Edit feature strategy",onClose:r,open:!0,children:t(oa,{})})})]})]})},cr=({values:e=[],updateValues:n,placeholder:a="",error:o,...s})=>{const i=l=>{const p=l.target.value.split(/,\s?/).map(h=>h.trim());n(p)},r=l=>{if(l.key==="Backspace"){const u=l.target.value;if(u.endsWith(", ")){l.preventDefault();const p=u.slice(0,-2);n(p.split(/,\s*/))}}};return t(Xt,{...s,error:o,placeholder:a,value:e?e.join(", "):"",onKeyDown:r,onChange:i,style:{width:"100%"},variant:"outlined",size:"small"})},lr=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"}}})),dr=d(Qt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),ur=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),pr=d(cr)(()=>({width:"100%"})),gr=d(Xt)(()=>({width:"100%"})),hr=({overrides:e,overridesDispatch:n})=>{const{context:a}=ct(),o=a.map(({name:r})=>({key:r,label:r})),s=r=>l=>{n({type:"UPDATE_VALUES_AT",payload:[r,l]})},i=r=>(l,u)=>{l==null||l.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[r,u||[]]})};return t(M,{children:e.map((r,l)=>{var g;const u=a.find(({name:b})=>b===r.contextName),p=((g=u==null?void 0:u.legalValues)==null?void 0:g.map(({value:b})=>b))||[],h=r.values.filter(b=>p.includes(b));return c(lr,{children:[t(dr,{id:"override-context-name",name:"contextName",label:"Context Field",value:r.contextName,options:o,onChange:b=>n({type:"UPDATE_TYPE_AT",payload:[l,b.target.value]})}),c(ur,{children:[t(I,{condition:Boolean(p&&p.length>0),show:t(sa,{multiple:!0,id:`override-select-${l}`,isOptionEqualToValue:(b,v)=>b===v,options:p,onChange:i(l),getOptionLabel:b=>b,value:h,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(gr,{...b,variant:"outlined",label:"Legal values"})}),elseShow:t(pr,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:r.values,updateValues:s(l)})}),t(ee,{title:"Remove",arrow:!0,children:t($e,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:l})},children:t(tt,{})})})]})]},`override=${l}`)})})},mr=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((r,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)}},fr=(e=[])=>f.useReducer(mr,e);var X=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(X||{});const yr=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})),Sr=d(ee)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),pn=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Dt=d(pn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),br=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),Cr=d(ra)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),vr=d("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex","& > div":{width:"100%"}})),Ot=d(Zt)(()=>({width:"100%"})),wr=d("div")(({theme:e})=>({marginLeft:e.spacing(3)})),Tr=d(Zt)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),xr=d("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),gn=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%"}}})),Ar=d(gn)({alignItems:"end",justifyContent:"space-between"}),Er=d(Qt)(({theme:e})=>({marginRight:e.spacing(10),[e.breakpoints.up("sm")]:{minWidth:e.spacing(20)}})),Ir=d(re)(({theme:e})=>({marginTop:e.spacing(-1),marginLeft:e.spacing(-1)})),Rr=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Fr={type:"string",value:""},kr=({variant:e,variants:n,updateVariant:a,removeVariant:o,apiPayload:s})=>{const[i,r]=f.useState(e.name),[l,u]=f.useState(e.weightType===X.FIX),[p,h]=f.useState(String(e.weight/10)),[g,b]=f.useState(e.payload||Fr),[v,T]=fr(e.overrides||[]),{context:R}=ct(),[y,C]=f.useState({}),w=m=>{C(S=>({...S,[m]:void 0}))},E=(m,S)=>{C(A=>({...A,[m]:S}))};f.useEffect(()=>{var m;w("percentage"),(m=s.error)!=null&&m.includes("%")&&E("percentage","Total weight must equal 100%")},[s.error]);const B=!e.new,D=n.filter(({id:m,weightType:S})=>m!==e.id&&S===X.VARIABLE).length>0,P=m=>{const S=m.weightType===X.VARIABLE,A=n.some(L=>L.weightType===X.FIX),V=n.filter(L=>L.weightType===X.VARIABLE).length===1;return A&&V&&S},O=m=>{w("name"),te(m,e.id)||E("name","A variant with that name already exists for this environment."),r(m)},$=m=>{(m===""||Z(m))&&h(m)},U=m=>{x(m)||E("payload","Invalid JSON.")},Y=()=>{R.length>0&&T({type:"ADD",payload:{contextName:R[0].name,values:[]}})},K=m=>Boolean(m.length),te=(m,S)=>B||!n.some(A=>A.name===m&&A.id!==S),Z=m=>{if(!l)return!0;if(m===""||m.match(/\.[0-9]{2,}$/))return!1;const S=Number(m);return S>=0&&S<=100},x=m=>{try{return m.type==="json"&&JSON.parse(m.value),!0}catch{return!1}};return f.useEffect(()=>{a({...e,name:i,weight:Number(l?p:100)*10,weightType:l?X.FIX:X.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:g.value?g:void 0,overrides:v.map(m=>({contextName:m.contextName,values:m.values})).filter(m=>m.values&&m.values.length>0),isValid:K(i)&&te(i,e.id)&&Z(p)&&x(g)&&!s.error})},[i,l,p,g,v]),f.useEffect(()=>{l||h(String(e.weight/10))},[e.weight]),c(yr,{children:[t(Sr,{arrow:!0,title:P(e)?"You need to have at least one variable variant":"Delete variant",children:t("div",{children:t($e,{"data-testid":`VARIANT_DELETE_BUTTON_${e.name}`,onClick:()=>o(e.id),disabled:P(e),children:t(tt,{})})})}),c(Ar,{children:[c(xr,{children:[t(pn,{children:"Variant name"}),t(br,{children:"This will be used to identify the variant in your code"}),t(Ot,{id:`variant-name-input-${e.id}`,"data-testid":"VARIANT_NAME_INPUT",label:"Variant name",error:Boolean(y.name),errorText:y.name,value:i,onChange:m=>O(m.target.value),disabled:B,required:!0})]}),t(I,{condition:D,show:c(wr,{children:[t(Cr,{label:"Custom percentage",control:t(ia,{"data-testid":"VARIANT_WEIGHT_CHECK",checked:l,onChange:m=>u(m.target.checked)})}),t(Tr,{"data-testid":"VARIANT_WEIGHT_INPUT",type:"number",label:"Variant weight",error:Boolean(y.percentage),errorText:y.percentage,value:p,onChange:m=>$(m.target.value),required:l,disabled:!l,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(ca,{position:"end",children:"%"})}})]})})]}),c(Dt,{children:["Payload",t(Ye,{tooltip:"Passed along with the the variant object."})]}),c(gn,{children:[t(Er,{id:"variant-payload-type",name:"type",label:"Type",value:g.type,options:Rr,onChange:m=>{w("payload"),b(S=>({...S,type:m.target.value}))}}),t(vr,{children:t(Ot,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:g.type!=="string",rows:g.type==="string"?1:4,value:g.value,onChange:m=>{w("payload"),b(S=>({...S,value:m.target.value}))},placeholder:g.type==="json"?'{ "hello": "world" }':"",onBlur:()=>U(g),error:Boolean(y.payload),errorText:y.payload})})]}),c(Dt,{children:["Overrides",t(Ye,{tooltip:"Here you can specify which users should get this variant."})]}),t(hr,{overrides:v,overridesDispatch:T}),t("div",{children:t(Ir,{onClick:Y,variant:"text",color:"primary",children:"Add override"})})]})},$r=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})),Pr=d(en,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Br=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})),Dr=d("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Or=d(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Vr=d(he)(({theme:e})=>({marginTop:e.spacing(4)})),Mr=d("div")({display:"flex",flexDirection:"column"}),Lr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Vt=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),_r=d(ye)(({theme:e})=>({margin:e.spacing(4,0)})),jr=d(la)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Nr=d("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),zr=d(re)(({theme:e})=>({marginLeft:e.spacing(3)})),Wr=({environment:e,open:n,setOpen:a,getApiPayload:o,getCrPayload:s,onConfirm:i})=>{var gt;const r=F("projectId"),l=F("featureId"),{uiConfig:u}=lt(),{context:p}=ct(),{defaultStickiness:h,loading:g}=da(r),{isChangeRequestConfigured:b}=oe(r),{data:v}=ve(r),{changeRequestInReviewOrApproved:T,alert:R}=ga(v),y=(e==null?void 0:e.variants)||[],[C,w]=f.useState([]),[E,B]=f.useState();f.useEffect(()=>{g||w(y.length?y.map(k=>({...k,isValid:!0,new:!1,id:_e()})):[{name:"",weightType:X.VARIABLE,weight:0,overrides:[],stickiness:(C==null?void 0:C.length)>0?C[0].stickiness:h,new:!0,isValid:!1,id:_e()}])},[n,g]);const D=(k,W)=>{w(ie=>yt(ie.map(Ae=>Ae.id===W?k:Ae),1e3))},P=()=>{const k=_e();w(W=>[...W,{name:"",weightType:X.VARIABLE,weight:0,overrides:[],stickiness:(W==null?void 0:W.length)>0?W[0].stickiness:h,new:!0,isValid:!1,id:k}]),B(k)};f.useEffect(()=>{if(E){const k=document.getElementById(`variant-name-input-${E}`);k==null||k.scrollIntoView({behavior:"smooth",block:"center"}),k==null||k.focus({preventScroll:!0}),B(void 0)}},[E]);const O=C.map(({new:k,isValid:W,id:ie,...Ae})=>Ae),$=o(y,O),U=s(O),Y=async k=>{k.preventDefault(),i(O)},K=()=>m?`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(U,void 0,2)}'`:`curl --location --request PATCH '${u.unleashUrl}/api/admin/projects/${r}/features/${l}/environments/${e==null?void 0:e.name}/variants' \\
|
|
5
|
-
--header 'Authorization: INSERT_API_KEY' \\
|
|
6
|
-
--header 'Content-Type: application/json' \\
|
|
7
|
-
--data-raw '${JSON.stringify($.patch,void 0,2)}'`,te=C.every(({isValid:k})=>k),Z=T((e==null?void 0:e.name)||""),x=Z?"Add to existing change request":"Add change to draft",m=b((e==null?void 0:e.name)||"")&&u.flags.crOnVariants,S=((gt=O[0])==null?void 0:gt.stickiness)||h,A=f.useMemo(()=>["default",...p.filter(k=>k.stickiness).map(k=>k.name)],[p]),V=A.map(k=>({key:k,label:k}));A.includes(S)||V.push({key:S,label:S});const L=async k=>{w(W=>W.map(ie=>({...ie,stickiness:k})))},_=k=>{L(k).catch(console.warn)},[q,xe]=f.useState();f.useEffect(()=>{xe(void 0),$.error&&xe($.error)},[$.error]);const pt=()=>{L(h).catch(console.warn),a(!1)};return g||S===""?t(ua,{}):t(Ke,{open:n,onClose:pt,label:"",children:c(pa,{modal:!0,title:"",description:"Variants allows you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:K,loading:!n,children:[c($r,{children:[c("div",{children:[t(Pr,{deprecated:!(e!=null&&e.enabled)}),t(Br,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ae,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:P,variant:"outlined",permission:ce,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(Dr,{onSubmit:Y,children:[t(I,{condition:Z,show:R,elseShow:t(I,{condition:Boolean(m),show:c(Or,{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(Mr,{children:C.map(k=>t(kr,{variant:k,variants:C,updateVariant:W=>D(W,k.id),removeVariant:()=>w(W=>yt(W.filter(ie=>ie.id!==k.id),1e3)),projectId:r,apiPayload:$},k.id))}),t(ae,{onClick:P,variant:"outlined",permission:ce,projectId:r,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(_r,{}),t(I,{condition:C.length>0,show:c(M,{children:[t(Lr,{children:t("p",{children:"Stickiness"})}),c(Vt,{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(jr,{value:S,label:"",editable:!0,onChange:k=>_(k.target.value)})})]}),elseShow:t(Vt,{children:"This environment has no variants. Get started by adding a variant."})}),c(Vr,{severity:"error",hidden:!Boolean(q),children:[t("strong",{children:"Error: "}),q]}),c(Nr,{children:[t(re,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!te,children:m?x:"Save variants"}),t(zr,{onClick:pt,children:"Cancel"})]})]})]})})},Ur=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)}})),qr=d("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Hr=d(en,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Gr=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})),Yr=d("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Kr=d("div")(({theme:e})=>({margin:e.spacing(3,0)})),Jr=d("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Xr=({environment:e,searchValue:n,children:a})=>{var i;const o=e.variants??[],s=((i=o[0])==null?void 0:i.stickiness)||"default";return c(Ur,{children:[c(qr,{children:[c("div",{children:[t(Hr,{deprecated:!e.enabled}),t(Gr,{deprecated:!e.enabled,children:e.name})]}),a]}),t(I,{condition:o.length>0,show:c(M,{children:[t(Kr,{children:t(ha,{variants:o,searchValue:n})}),t(I,{condition:o.length>1,show:c(M,{children:[c(Jr,{children:[t("p",{children:"Stickiness:"}),t(fe,{children:s})]}),c(Yr,{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"})]})]})})]})})]})},Qr=d(at)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Zr=({environment:e,permission:n,projectId:a,environmentId:o,onCopyVariantsFrom:s,otherEnvsWithVariants:i})=>{const[r,l]=f.useState(null),u=Boolean(r),p=e.variants??[];return t(I,{condition:i.length>0&&p.length===0,show:c(M,{children:[t(ae,{onClick:h=>{l(h.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":u?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:o,children:"Copy variants from"}),t(Pe,{anchorEl:r,open:u,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(h=>t(Be,{onClick:()=>s(h,e),children:t(Qr,{children:`Copy from ${h.name}`})},h.name))})]})})},ei=({permission:e,projectId:n,environment:a,checked:o,onClick:s,...i})=>{const r=ma(e,n,a);return c(Be,{disabled:!r,onClick:s,...i,children:[t(fa,{checked:o}),a]})},ti=d(Pe)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),ni=d("div")(({theme:e})=>({margin:e.spacing(1,2)})),ai=d(re)(({theme:e})=>({marginTop:e.spacing(2)})),oi=({current:e,environments:n,permission:a,projectId:o,onSubmit:s})=>{var R;const[i,r]=f.useState(null),l=Boolean(i),[u,p]=f.useState([]),h=y=>{p(C=>[...C,y])},g=y=>{p(C=>C.filter(({name:w})=>w!==y.name))},b=y=>{u.includes(y)?g(y):h(y)},v=()=>{p([]),r(null)},T=((R=n.find(y=>y.name===e))==null?void 0:R.variants)??[];return t(I,{condition:T.length>0&&n.length>1,show:c(M,{children:[t(re,{onClick:y=>{r(y.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",children:"Push to environment"}),c(ti,{anchorEl:i,open:l,onClose:()=>r(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(ei,{projectId:o,permission:a,environment:y.name,checked:u.includes(y),onClick:()=>b(y)},y.name)),c(ni,{children:[t(ye,{}),c(ai,{variant:"outlined",onClick:()=>{s(u),v()},disabled:u.length===0,children:["Push to selected (",u.length,")"]})]})]})]})})},si=d(he)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),ri=d("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),ii=()=>{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:h,overrideVariantsInEnvironments:g}=Te(),{refetch:b}=ve(i),{addChange:v}=nt(),{isChangeRequestConfigured:T}=oe(i),[R,y]=f.useState(""),[C,w]=f.useState(),[E,B]=f.useState(!1),D=f.useMemo(()=>{var x;return((x=l==null?void 0:l.environments)==null?void 0:x.map(m=>({...m,crEnabled:e.flags.crOnVariants&&T(m.name)})))||[]},[l.environments,e.flags.crOnVariants]),P=(x,m)=>ba(x,m),O=(x,m)=>{try{const S=Sa(m,1e3);return{patch:P(x,S)}}catch(S){return{patch:[],error:z(S)}}},$=x=>({feature:r,action:"patchVariant",payload:{variants:x}}),U=async(x,m)=>{if(x.crEnabled)await v(i,x.name,$(m)),b();else{const S=x.variants??[],{patch:A,error:V}=O(S,m);if(A.length===0)return;if(V){n({type:"error",title:V});return}await h(i,r,x.name,A)}u()},Y=async(x,m)=>{try{const S=m.filter(({crEnabled:q})=>q),A=m.filter(({crEnabled:q})=>!q);S.length&&await Promise.all(S.map(q=>v(i,q.name,$(x)))),A.length&&await g(i,r,x,A.map(({name:q})=>q)),b(),u();const V=A.length?`Variants pushed to ${A.length===1?A[0].name:`${A.length} environments`}`:"",L=S.length?`Variants push added to ${S.length===1?`${S[0].name} draft`:`${S.length} drafts`}`:"",_=`${V}${V&&L?". ":""}${L}`;n({title:_,type:"success"})}catch(S){a(z(S))}},K=x=>{w(x),B(!0)},te=async x=>{if(C)try{await U(C,x),B(!1),n({title:C.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(m){a(z(m))}},Z=async(x,m)=>{try{const S=x.variants??[];await U(m,S),n({title:m.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(S){a(z(S))}};return c(dt,{isLoading:p,header:t(ya,{title:"Variants",actions:t(I,{condition:!s,show:t(M,{children:t(St,{initialValue:R,onChange:y})})}),children:t(I,{condition:s,show:t(St,{initialValue:R,onChange:y})})}),children:[c(si,{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(x=>{var S;const m=D.filter(({name:A,variants:V})=>A!==x.name&&(V==null?void 0:V.length));return t(Xr,{environment:x,searchValue:R,children:c(ri,{children:[t(oi,{current:x.name,environments:D,permission:ce,projectId:i,onSubmit:A=>Y(x.variants??[],A)}),t(Zr,{environment:x,permission:ce,projectId:i,environmentId:x.name,onCopyVariantsFrom:Z,otherEnvsWithVariants:m}),t(I,{condition:Boolean((S=x.variants)==null?void 0:S.length),show:t(Q,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>K(x),permission:ce,projectId:i,environmentId:x.name,tooltipProps:{title:"Edit variants"},children:t(me,{})}),elseShow:t(ae,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>K(x),variant:"outlined",permission:ce,projectId:i,environmentId:x.name,children:"Add variant"})})]})},x.name)}),t(Wr,{environment:C,open:E,setOpen:B,getApiPayload:O,getCrPayload:$,onConfirm:te})]})},ci=be("api/admin/client-metrics/features"),hn=(e,n)=>{const a=be(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:o,error:s}=Qe(a,()=>li(a)),i=f.useCallback(()=>{Ze(ci).catch(console.warn)},[]);return{featureMetrics:o==null?void 0:o.data,loading:!s&&!o,refetchFeatureMetrics:i,error:s}},li=e=>fetch(e).then(ke("Features")).then(n=>n.json()).then(),Se=48,di=({hoursBack:e,setHoursBack:n})=>{const a=o=>{n(ui(o))};return t(Ca,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:pi,value:String(e),onChange:a,fullWidth:!0})},ui=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Se}},pi=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Se}`,label:`Last ${Se} hours`}],gi=({metrics:e,tableSectionId:n})=>{const a=De(tn.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:Mt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:va}},Le.useGlobalFilter,Le.useSortBy);return wa([{condition:a,columns:["appName","environment"]}],p,Mt),e.length===0?null:c(Ta,{...s(),rowHeight:"standard",id:n,children:[t(xa,{headerGroups:r}),t(Aa,{...i(),children:l.map(h=>(u(h),t(Ea,{hover:!0,...h.getRowProps(),children:h.cells.map(g=>t(Ia,{...g.getCellProps(),children:g.render("Cell")}))})))})]})},Mt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ra,{icon:t(yo,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Fa,{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"}],hi=({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(ln,{...n,totalYes:a,totalNo:o})},mi=({metrics:e,hoursBack:n})=>{const a=bt(),o=bt();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:tn.palette.divider,children:t(fi,{metrics:e,hoursBack:n,statsSectionId:a})}),t(H,{mt:4,children:t(hi,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:o})}),t(H,{mt:4,children:t(gi,{metrics:e,tableSectionId:o})})]})},fi=ka.lazy(()=>import("./FeatureMetricsChart-66e2ebdf.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]},yi=e=>{const[n,a]=Xe(e),o=f.useCallback(s=>a(String(s)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,o]},Si=d("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),bi=d("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),Ci=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}})),Lt=({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(Si,{children:e}),t(bi,{children:i.map(r=>t(Ci,{children:t(Yt,{label:r,onClick:s(r),"aria-pressed":r===a,sx:$a})},r))})]})},vi=d("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),wi=()=>{const e=F("projectId"),n=F("featureId"),a=Ti(e,n),o=xi(n);Kt("Metrics");const[s=Se,i]=yi("hoursBack"),{featureMetrics:r}=hn(n,s),[l,u]=f.useState(r);f.useEffect(()=>{r&&u(r)},[r]);const p=Array.from(a)[0],h=Array.from(o)[0],[g=p,b]=Xe("environment"),[v=h,T]=Xe("application"),R=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===g).filter(y=>y.appName===v),[l,g,v]);return R?c(dt,{children:[c(ne,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(ne,{item:!0,xs:12,md:5,children:t(I,{condition:a.size>0,show:t(Lt,{title:"Environments",values:a,value:g,setValue:b})})}),t(ne,{item:!0,xs:12,md:5,children:t(I,{condition:o.size>0,show:t(Lt,{title:"Applications",values:o,value:v,setValue:T})})}),t(ne,{item:!0,xs:12,md:2,children:t(vi,{children:t(di,{hoursBack:s,setHoursBack:i})})})]}),t(mi,{metrics:R,hoursBack:s})]}):null},Ti=(e,n)=>{const{feature:a}=j(e,n),o=a.environments.map(s=>s.name);return new Set(o)},xi=e=>{const{featureMetrics:n=[]}=hn(e,Se),a=n.map(o=>o.appName);return new Set(a)},Ai=(e,n)=>{const a=new Set(e),o=new Set(n);return a.size!==o.size?!1:[...a].every(s=>o.has(s))},_t=d("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),jt=d(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Ei=d(rt)({padding:0}),Ii=({projectId:e,open:n,onClose:a,onClick:o,feature:s,changeRequests:i})=>{const r=F("projectId"),{project:l}=nn(e),{isChangeRequestConfiguredInAnyEnv:u}=oe(e),p=u(),h=f.useMemo(()=>Ai(s.environments.map(b=>b.name),l.environments),[s,l]),g=i?i.length>0:!1;return t(I,{condition:h&&!g&&!p,show:t(de,{open:n,onClose:a,onClick:o,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(_t,{children:[t(jt,{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(_t,{children:[t(jt,{severity:"warning",children:"Cannot proceed with the move"}),t(I,{condition:!h,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(I,{condition:g,show:c(M,{children:[t("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t(Ei,{children:i==null?void 0:i.map(b=>t(Re,{children:c(J,{to:`/projects/${r}/change-requests/${b.id}`,children:["View change request"," ",b.id]})},b.id))})]})}),t(I,{condition:p,show:c("p",{children:["You're not allowed to move the feature to project"," ",t(J,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Ri=e=>fetch(e).then(ke("ChangeRequest")).then(n=>n.json()),Fi=(e,n)=>{const{data:a,error:o,mutate:s}=Pa([],be(`api/admin/projects/${e}/change-requests/pending/${n}`),Ri);return{changeRequests:a,loading:!o&&!a,refetch:s,error:o}},ki=()=>{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(),[h,g]=f.useState(n),{projects:b}=Ba(),v=ge(),{changeRequests:T}=Fi(n,a),R=async()=>{try{h&&(await l(n,a,h),s(),u({title:"Project changed",type:"success"}),r(!1),v(`/projects/${h}/features/${a}/settings`,{replace:!0}))}catch(C){p(z(C))}},y=f.useMemo(()=>b.map(C=>C.id).filter(C=>e(Ct,C)),[b,e]);return y.length===0?null:c(M,{children:[t(Da,{value:h,onChange:g,label:"Project",filter:C=>y.includes(C),enabled:!0}),t(ae,{permission:Ct,onClick:()=>r(!0),disabled:h===n,projectId:n,children:"Save"}),t(Ii,{changeRequests:T,projectId:h,open:i,feature:o,onClose:()=>r(!1),onClick:R})]})},$i=d("div")({display:"flex",alignItems:"center"}),Pi=d(N)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),Bi=({projectId:e,featureId:n})=>{var i;const{feature:a}=j(e,n),o=ge();return c(M,{children:[c($i,{children:[t(Pi,{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",Di=d("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Oi=d("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),Vi=()=>{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(Di,{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(Oi,{children:[t(I,{condition:a===Ee,show:t(Bi,{projectId:e,featureId:n})}),t(I,{condition:a===Ge&&s.flags.P,show:t(ki,{})})]})]})})},Mi=({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"})}),Nt=d("strong")({wordBreak:"break-all"}),Li=()=>{const e=F("projectId"),n=F("featureId"),{archivedFeatures:a}=Oa(),o=Va(e,{name:n});return a?a.some(i=>i.name===n)?c("p",{children:["The feature ",t(Nt,{children:n})," has been archived. You can find it on the"," ",t(J,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(Nt,{children:n})," does not exist. Would you like to"," ",t(J,{to:o,children:"create it"}),"?"]}):null},_i=d("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),ji=d("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Ni=d("div")({display:"flex",alignItems:"center"}),zi=d("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Wi=d("div")({flexShrink:0,display:"flex"}),Ui=d("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),qi=d("div")(({theme:e})=>({padding:e.spacing(0,4)})),Hi=d(Ma)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Qi=()=>{const e=F("projectId"),n=F("featureId"),{refetch:a}=nn(e),{favorite:o,unfavorite:s}=La(),{refetchFeature:i}=j(e,n),[r,l]=f.useState(!1),[u,p]=f.useState(!1),[h,g]=f.useState(!1),b=De(`(max-width:${500}px)`),{feature:v,loading:T,error:R,status:y}=j(e,n),C=ge(),{pathname:w}=_a(),E=ja(T),B=`/projects/${e}/features/${n}`,D=[{title:"Overview",path:`${B}`,name:"overview"},{title:"Metrics",path:`${B}/metrics`,name:"Metrics"},{title:"Variants",path:`${B}/variants`,name:"Variants"},{title:"Settings",path:`${B}/settings`,name:"Settings"},{title:"Event log",path:`${B}/logs`,name:"Event log"}],P=D.find($=>$.path===w)??D[0],O=async()=>{v!=null&&v.favorite?await s(e,v.name):await o(e,v.name),i()};return y===404?t(Li,{}):R!==void 0?t("div",{ref:E}):c("div",{ref:E,children:[c(_i,{children:[c(ji,{children:[c(Ni,{children:[t(Na,{onClick:O,isFavorite:v==null?void 0:v.favorite}),c(zi,{"data-loading":!0,children:[v.name," "]}),t(I,{condition:!b,show:t(Mi,{stale:v==null?void 0:v.stale})})]}),c(Wi,{children:[t(Q,{permission:za,projectId:e,"data-loading":!0,component:J,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Wa,{})}),t(Q,{permission:Ua,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>p(!0),children:t(oo,{})}),t(Q,{onClick:()=>g(!0),permission:le,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(so,{})}),t(Q,{onClick:()=>l(!0),permission:le,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(qa,{})})]})]}),t(Ui,{}),t(qi,{children:t(Ha,{value:P.path,indicatorColor:"primary",textColor:"primary",children:D.map($=>t(Hi,{label:$.title,value:$.path,onClick:()=>C($.path)},$.title))})})]}),c(Jt,{children:[t(se,{path:"metrics",element:t(wi,{})}),t(se,{path:"logs",element:t(Co,{})}),t(se,{path:"variants",element:t(ii,{})}),t(se,{path:"settings",element:t(Vi,{})}),t(se,{path:"*",element:t(ir,{})})]}),t(ro,{isOpen:u,onConfirm:()=>{a(),C(`/projects/${e}`)},onClose:()=>p(!1),projectId:e,featureIds:[n]}),t(io,{isStale:v.stale,isOpen:h,onClose:()=>{g(!1),i()},featureId:n,projectId:e}),t(un,{open:r,setOpen:l})]})};export{Qi as default};
|