@@ -9,21 +9,36 @@ import {
99} from 'common/theme/tokens'
1010import { Res } from 'common/types/responses'
1111
12- const select = ( label : string , ariaLabel : string ) => (
12+ const PROJECTS = [
13+ 'All Projects' ,
14+ 'Checkout' ,
15+ 'Mobile app' ,
16+ 'Internal tools' ,
17+ 'Marketing site' ,
18+ ]
19+
20+ const select = ( label : string , ariaLabel : string , options : string [ ] ) => (
1321 < div style = { { minWidth : 210 } } >
1422 < Select
1523 aria-label = { ariaLabel }
1624 value = { { label, value : label } }
17- options = { [ { label, value : label } ] }
25+ options = { options . map ( ( option ) => ( { label : option , value : option } ) ) }
1826 onChange = { ( ) => { } }
1927 />
2028 </ div >
2129)
2230
23- const filters = ( period : string ) => (
31+ const PERIODS = [
32+ 'Current billing period' ,
33+ 'Previous billing period' ,
34+ 'Last 90 days' ,
35+ 'Last 30 days' ,
36+ ]
37+
38+ const filters = ( period : string , project = 'All Projects' ) => (
2439 < Row className = 'gap-2' >
25- { select ( period , 'Period' ) }
26- { select ( 'All Projects' , 'Project' ) }
40+ { select ( period , 'Period' , PERIODS ) }
41+ { select ( project , 'Project' , PROJECTS ) }
2742 </ Row >
2843)
2944
@@ -44,11 +59,17 @@ const BREAKDOWN_ROWS = [
4459 } ,
4560]
4661
47- const breakdown = ( scope : string ) => (
62+ const scaleRows = ( factor : number ) =>
63+ BREAKDOWN_ROWS . map ( ( row ) => ( {
64+ ...row ,
65+ value : Math . round ( row . value * factor ) ,
66+ } ) )
67+
68+ const breakdown = ( scope : string , factor = 1 ) => (
4869 < UsageBreakdown
4970 dimension = 'request-type'
5071 onChangeDimension = { ( ) => { } }
51- rows = { BREAKDOWN_ROWS }
72+ rows = { scaleRows ( factor ) }
5273 scope = { scope }
5374 />
5475)
@@ -192,6 +213,42 @@ export const WithoutAPlanLimit: Story = {
192213 } ,
193214}
194215
216+ /**
217+ * A closed period, so the chart is a complete curve rather than one still
218+ * being drawn. The meter stays on the current period, which is the only one
219+ * that can still be acted on.
220+ */
221+ export const PreviousBillingPeriod : Story = {
222+ args : {
223+ breakdown : breakdown ( 'All projects · Previous billing period' , 1.34 ) ,
224+ data : usage ( 31 , 61000 ) ,
225+ filters : filters ( 'Previous billing period' ) ,
226+ hasBillingPeriod : true ,
227+ limit : 2000000 ,
228+ periodLabel : 'Previous billing period' ,
229+ showPlanCeiling : false ,
230+ total : paid . totals . total ,
231+ } ,
232+ }
233+
234+ /**
235+ * The meter keeps answering for the organisation while the chart, the
236+ * breakdown and the note below the bar follow the chosen project.
237+ */
238+ export const FilteredToAProject : Story = {
239+ args : {
240+ breakdown : breakdown ( 'Checkout · Current billing period' , 0.38 ) ,
241+ data : usage ( 18 , 26600 ) ,
242+ filters : filters ( 'Current billing period' , 'Checkout' ) ,
243+ hasBillingPeriod : true ,
244+ limit : 2000000 ,
245+ meterNote : 'Checkout accounts for 38% of that usage.' ,
246+ periodLabel : 'Current billing period' ,
247+ showPlanCeiling : false ,
248+ total : paid . totals . total ,
249+ } ,
250+ }
251+
195252export const NoUsageYet : Story = {
196253 args : {
197254 data : usage ( 0 , 0 ) ,
0 commit comments