1- import { useCallback , useEffect , useMemo , useRef , useState , type ReactNode } from "react" ;
1+ import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
22import { useI18n , type TFn , type Locale } from "../i18n/shared" ;
33import { formatTokens } from "../format-tokens" ;
44import { EmptyState , Notice } from "../ui" ;
@@ -449,14 +449,12 @@ function UsageModelsTable({
449449 onModelQuery,
450450 locale,
451451 t,
452- workspace = false ,
453452} : {
454453 models : UsageModel [ ] ;
455454 modelQuery : string ;
456455 onModelQuery : ( query : string ) => void ;
457456 locale : Locale ;
458457 t : TFn ;
459- workspace ?: boolean ;
460458} ) {
461459 const searchLabel = t ( "usage.search.models" ) ;
462460 const sectionLabel = t ( "usage.section.models" ) ;
@@ -499,15 +497,6 @@ function UsageModelsTable({
499497 </ div >
500498 ) ;
501499
502- if ( workspace ) {
503- return (
504- < UsageWorkspaceSection title = { sectionLabel } titleId = { titleId } >
505- < div className = "usw-section-toolbar" > { searchInput } </ div >
506- { table }
507- </ UsageWorkspaceSection >
508- ) ;
509- }
510-
511500 return (
512501 < section className = "panel" style = { { marginTop : 16 } } aria-labelledby = { titleId } >
513502 < div className = "panel-head" >
@@ -523,12 +512,10 @@ function UsageProvidersTable({
523512 providers,
524513 locale,
525514 t,
526- workspace = false ,
527515} : {
528516 providers : UsageProvider [ ] ;
529517 locale : Locale ;
530518 t : TFn ;
531- workspace ?: boolean ;
532519} ) {
533520 const sectionLabel = t ( "usage.section.providers" ) ;
534521 const titleId = "usage-providers-title" ;
@@ -559,14 +546,6 @@ function UsageProvidersTable({
559546 </ div >
560547 ) ;
561548
562- if ( workspace ) {
563- return (
564- < UsageWorkspaceSection title = { sectionLabel } titleId = { titleId } >
565- { table }
566- </ UsageWorkspaceSection >
567- ) ;
568- }
569-
570549 return (
571550 < section className = "panel" style = { { marginTop : 16 } } aria-labelledby = { titleId } >
572551 < h3 id = { titleId } className = "panel-title" > { sectionLabel } </ h3 >
@@ -578,11 +557,9 @@ function UsageProvidersTable({
578557function UsageCoveragePanel ( {
579558 summary,
580559 t,
581- workspace = false ,
582560} : {
583561 summary : UsageSummaryTotals ;
584562 t : TFn ;
585- workspace ?: boolean ;
586563} ) {
587564 const sectionLabel = t ( "usage.section.coverage" ) ;
588565 const titleId = "usage-coverage-title" ;
@@ -599,14 +576,6 @@ function UsageCoveragePanel({
599576 </ >
600577 ) ;
601578
602- if ( workspace ) {
603- return (
604- < UsageWorkspaceSection title = { sectionLabel } titleId = { titleId } >
605- { body }
606- </ UsageWorkspaceSection >
607- ) ;
608- }
609-
610579 return (
611580 < section className = "panel" style = { { marginTop : 16 } } aria-labelledby = { titleId } >
612581 < h3 id = { titleId } className = "panel-title" > { sectionLabel } </ h3 >
@@ -615,134 +584,6 @@ function UsageCoveragePanel({
615584 ) ;
616585}
617586
618- function UsageWorkspaceSection ( {
619- title,
620- titleId,
621- children,
622- } : {
623- title : string ;
624- titleId : string ;
625- children : ReactNode ;
626- } ) {
627- return (
628- < section className = "usw-section" aria-labelledby = { titleId } >
629- < h3 id = { titleId } className = "h-section" > { title } </ h3 >
630- { children }
631- </ section >
632- ) ;
633- }
634-
635- /**
636- * Workspace layout for the Usage tab: a left rail lists the report sections
637- * (Overview, Models, Providers, Coverage) and the main pane renders the selected
638- * one. Section bodies reuse the same panel components as the classic stacked view.
639- * The shell mounts immediately (including while loading/empty) so workspace mode
640- * never flashes the classic EmptyState first.
641- */
642- function UsageWorkspaceBody ( {
643- data,
644- loading,
645- heatmap,
646- weekBars,
647- activeDays,
648- filteredModels,
649- modelQuery,
650- onModelQuery,
651- sortedProviders,
652- range,
653- selectedSection,
654- onSelectSection,
655- locale,
656- t,
657- } : {
658- data : UsageResponse | null ;
659- loading : boolean ;
660- heatmap : ReturnType < typeof buildHeatmap > ;
661- weekBars : UsageDay [ ] ;
662- activeDays : number ;
663- filteredModels : UsageModel [ ] ;
664- modelQuery : string ;
665- onModelQuery : ( query : string ) => void ;
666- sortedProviders : UsageProvider [ ] ;
667- range : Range ;
668- selectedSection : string ;
669- onSelectSection : ( id : string ) => void ;
670- locale : Locale ;
671- t : TFn ;
672- } ) {
673- const empty = ! ! data && data . summary . requests === 0 ;
674- const sections = [
675- {
676- id : "overview" ,
677- label : t ( "usage.section.overview" ) ,
678- meta : data ? `${ data . summary . requests } ` : "—" ,
679- body : data ? (
680- < >
681- < UsageSummaryCards summary = { data . summary } activeDays = { activeDays } locale = { locale } t = { t } />
682- < UsageHeatmapPanel range = { range } heatmap = { heatmap } weekBars = { weekBars } locale = { locale } t = { t } />
683- </ >
684- ) : null ,
685- } ,
686- {
687- id : "models" ,
688- label : t ( "usage.section.models" ) ,
689- meta : data ? `${ data . models . length } ` : "—" ,
690- body : data
691- ? < UsageModelsTable models = { filteredModels } modelQuery = { modelQuery } onModelQuery = { onModelQuery } locale = { locale } t = { t } workspace />
692- : null ,
693- } ,
694- {
695- id : "providers" ,
696- label : t ( "usage.section.providers" ) ,
697- meta : data ? `${ data . providers . length } ` : "—" ,
698- body : data
699- ? < UsageProvidersTable providers = { sortedProviders } locale = { locale } t = { t } workspace />
700- : null ,
701- } ,
702- {
703- id : "coverage" ,
704- label : t ( "usage.section.coverage" ) ,
705- meta : data ? formatPct ( data . summary . coverageRatio ) : "—" ,
706- body : data ? < UsageCoveragePanel summary = { data . summary } t = { t } workspace /> : null ,
707- } ,
708- ] ;
709- const selected = sections . find ( s => s . id === selectedSection ) ?? sections [ 0 ] ;
710- const mainBody = loading && ! data
711- ? < EmptyState title = { t ( "usage.loading" ) } />
712- : empty
713- ? < EmptyState title = { t ( "usage.empty" ) } />
714- : selected . body ;
715-
716- return (
717- < div className = "usage-workspace-shell" >
718- < div className = "usage-workspace-root" >
719- < aside className = "usage-workspace-rail" aria-label = { t ( "usage.workspace.sections" ) } >
720- < div className = "usage-workspace-rail-header" >
721- < span className = "usage-workspace-rail-title" > { t ( "usage.title" ) } </ span >
722- </ div >
723- < div className = "usage-workspace-rail-list" >
724- { sections . map ( s => (
725- < button
726- key = { s . id }
727- type = "button"
728- className = { `usage-workspace-rail-row${ selectedSection === s . id ? " usage-workspace-rail-row--selected" : "" } ` }
729- onClick = { ( ) => onSelectSection ( s . id ) }
730- aria-current = { selectedSection === s . id ? "true" : undefined }
731- >
732- < span className = "usage-workspace-rail-name" > { s . label } </ span >
733- < span className = "usage-workspace-rail-meta" > { s . meta } </ span >
734- </ button >
735- ) ) }
736- </ div >
737- </ aside >
738- < section className = "usage-workspace-main" aria-label = { t ( "usage.workspace.report" ) } >
739- < div className = "usw-body" > { mainBody } </ div >
740- </ section >
741- </ div >
742- </ div >
743- ) ;
744- }
745-
746587export default function Usage ( { apiBase } : { apiBase : string } ) {
747588 const { t, locale } = useI18n ( ) ;
748589 const [ range , setRange ] = useState < Range > ( "30d" ) ;
@@ -751,7 +592,6 @@ export default function Usage({ apiBase }: { apiBase: string }) {
751592 const [ loading , setLoading ] = useState ( true ) ;
752593 const [ error , setError ] = useState < string | null > ( null ) ;
753594 const [ modelQuery , setModelQuery ] = useState ( "" ) ;
754- const [ selectedSection , setSelectedSection ] = useState ( "overview" ) ;
755595
756596 const fetchUsage = useCallback ( async ( nextRange : Range , nextSurface : UsageSurface , signal : AbortSignal ) => {
757597 setLoading ( true ) ;
@@ -823,24 +663,19 @@ export default function Usage({ apiBase }: { apiBase: string }) {
823663 { t ( "common.retry" ) }
824664 </ button >
825665 </ Notice >
826- ) : (
827- < UsageWorkspaceBody
828- data = { data }
829- loading = { loading }
830- heatmap = { heatmap }
831- weekBars = { weekBars }
832- activeDays = { activeDays }
833- filteredModels = { filteredModels }
834- modelQuery = { modelQuery }
835- onModelQuery = { setModelQuery }
836- sortedProviders = { sortedProviders }
837- range = { range }
838- selectedSection = { selectedSection }
839- onSelectSection = { setSelectedSection }
840- locale = { locale }
841- t = { t }
842- />
843- ) }
666+ ) : loading && ! data ? (
667+ < EmptyState title = { t ( "usage.loading" ) } />
668+ ) : data ?. summary . requests === 0 ? (
669+ < EmptyState title = { t ( "usage.empty" ) } />
670+ ) : data ? (
671+ < >
672+ < UsageSummaryCards summary = { data . summary } activeDays = { activeDays } locale = { locale } t = { t } />
673+ < UsageHeatmapPanel range = { range } heatmap = { heatmap } weekBars = { weekBars } locale = { locale } t = { t } />
674+ < UsageModelsTable models = { filteredModels } modelQuery = { modelQuery } onModelQuery = { setModelQuery } locale = { locale } t = { t } />
675+ < UsageProvidersTable providers = { sortedProviders } locale = { locale } t = { t } />
676+ < UsageCoveragePanel summary = { data . summary } t = { t } />
677+ </ >
678+ ) : null }
844679 </ >
845680 ) ;
846681}
0 commit comments