UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

2 lines (1 loc) 5.09 kB
import{s as c,bs as E,j as e,N as d,cK as v,jR as f,bc as y,b9 as B,cm as q,r as A,bb as I,cY as F,cJ as P,C as p,V as x,L as j,jn as _,jg as M,jh as N,ji as k,jj as $,jk as z,jl as H,jm as O}from"./index-BAMIkcom.js";import{a as W}from"./formatTickValue-Csg87IVi.js";import{u as Y,a as G,B as J,S as K,T as V,P as Q,n as X,g as Z}from"./networkTrafficUsageHighlightPlugin-Dje5Vuvo.js";import{p as ee,c as l}from"./LazyAdminExport-BOTczpO1.js";import"./RoleCell-Da0TjMne.js";import"./useApiTokens-Btk4Hd2u.js";import"./PercentageDonut-BoaVP9ed.js";const S=c("article")(({theme:s})=>({minWidth:"200px",border:`2px solid ${s.palette.divider}`,borderRadius:s.shape.borderRadiusLarge,padding:s.spacing(3),display:"flex",flexDirection:"column",gap:s.spacing(2)})),T=c("h3")(({theme:s})=>({margin:0,fontSize:s.typography.body1.fontSize})),w=c("dl")(({theme:s})=>({display:"flex",flexDirection:"column",gap:s.spacing(2.5),padding:0,margin:0})),a=c("div")(({theme:s})=>({display:"flex",flexFlow:"row wrap",justifyContent:"space-between",gap:s.spacing(1,3),fontSize:s.typography.body2.fontSize,color:s.palette.text.secondary,"& dd":{margin:0,color:s.palette.text.primary}})),se=s=>{const r=n=>n.toLocaleString("en-US",{month:"short",year:"numeric"});if(s.grouping==="monthly"){const n=new Date,t=f(n,s.monthsBack),o=f(n,1);return`Average requests from ${r(t)} to ${r(o)}`}return`Requests used in ${r(ee(s.month))}`},ne=({period:s,usageTotal:r,includedTraffic:n,purchasedTraffic:t,currentMonth:o})=>{const{locationSettings:i}=E();return e.jsxs(S,{children:[e.jsx(T,{children:"Number of requests to Unleash"}),e.jsxs(w,{children:[e.jsxs(a,{children:[e.jsx("dt",{children:se(s)}),e.jsx("dd",{children:e.jsxs(d,{color:n>0?r<=n?"success":"error":"neutral",children:[r.toLocaleString(i.locale??"en-US")," ","requests"]})})]}),n>0&&e.jsxs(a,{children:[e.jsx("dt",{children:"Included in your plan"}),e.jsxs("dd",{children:[n.toLocaleString("en-US")," requests"]})]}),t>0&&o&&e.jsxs(a,{children:[e.jsx("dt",{children:"Additional traffic purchased"}),e.jsxs("dd",{children:[t.toLocaleString("en-US")," requests"]})]}),n>0&&o&&e.jsxs(a,{children:[e.jsx("dt",{children:"Total traffic available"}),e.jsxs("dd",{children:[(n+t).toLocaleString("en-US")," ","requests"]})]})]})]})},te=({overages:s,overageCost:r,estimatedMonthlyCost:n})=>e.jsxs(S,{children:[e.jsx(T,{children:"Accrued traffic charges"}),e.jsxs(w,{children:[e.jsxs(a,{children:[e.jsxs("dt",{children:["Request overages this month (",e.jsx(v,{href:"https://www.getunleash.io/pricing",children:"pricing"}),")"]}),e.jsxs("dd",{children:[s.toLocaleString()," requests"]})]}),e.jsxs(a,{children:[e.jsx("dt",{children:"Accrued traffic charges"}),e.jsx("dd",{children:e.jsxs(d,{color:"secondary",children:[r," USD"]})})]}),n>0&&e.jsxs(a,{children:[e.jsx("dt",{children:"Estimated charges based on current usage"}),e.jsx("dd",{children:e.jsxs(d,{color:"secondary",children:[n," USD"]})})]})]})]}),re=53,oe=259,m=1e6,ae=(s,r)=>!s||r==="pay-as-you-go"?re:oe;function ie(s,r,n){return s===void 0?ae(r,n):s}function ce(s){return s===void 0?0:s}const le=()=>{const{isEnterprise:s,uiConfig:r}=y(),n=B("/api/instance/trafficBundles"),{data:t,error:o,mutate:i}=q(n,de);return{trafficBundles:A.useMemo(()=>({includedTraffic:ie(t==null?void 0:t.includedTraffic,s(),r.billing)*m,purchasedTraffic:ce(t==null?void 0:t.purchasedTraffic)*m}),[t]),loading:!o&&!t,refetch:i}},de=s=>fetch(s).then(I("configuration")).then(r=>r.json()),ue=c("div")(({theme:s})=>({display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, max-content))",flex:1,gap:s.spacing(2,4)})),ye=()=>{F("Network - Data Usage");const s=P("estimateTrafficDataCost"),{isOss:r}=y(),{trafficBundles:n}=le(),t=n.includedTraffic+n.purchasedTraffic,{chartDataSelection:o,setChartDataSelection:i,options:u}=Y(t),{chartData:C,usageTotal:h,overageCost:g,estimatedMonthlyCost:b,requestSummaryUsage:L}=G(t,o),U=o.grouping==="daily"&&o.month===l&&t>0&&h-t>0&&s,D=o.grouping==="daily"&&o.month===l,R=(o.grouping==="monthly"||o.month===l)&&t>0&&g>0;return e.jsx(p,{condition:r(),show:e.jsx(x,{severity:"warning",children:"Not enabled."}),elseShow:e.jsxs(e.Fragment,{children:[e.jsx(p,{condition:R,show:e.jsxs(x,{severity:"warning",sx:{mb:4},children:[e.jsx(J,{children:"Heads up!"})," You are currently consuming more requests than your plan includes and will be billed according to our terms. Please see"," ",e.jsx(j,{to:"https://www.getunleash.io/pricing",children:"this page"})," ","for more information. In order to reduce your traffic consumption, you may configure an"," ",e.jsx(j,{to:"https://docs.getunleash.io/unleash-edge",children:"Unleash Edge instance"})," ","in your own datacenter."]})}),e.jsxs(K,{children:[e.jsxs(V,{children:[e.jsxs(ue,{children:[e.jsx(ne,{period:o,usageTotal:L,includedTraffic:n.includedTraffic,purchasedTraffic:n.purchasedTraffic,currentMonth:D}),U&&e.jsx(te,{overageCost:g,overages:h-t,estimatedMonthlyCost:b})]}),e.jsx(Q,{selectedPeriod:o,setPeriod:i})]}),e.jsx(_,{data:C,plugins:[X],options:u,"aria-label":Z(o)})]})]})})};M.register(W,N,k,$,z,H,O);export{ye as default};