@@ -627,7 +627,7 @@ function UsageWorkspaceSection({
627627} ) {
628628 return (
629629 < section className = "usw-section" aria-labelledby = { titleId } >
630- < div id = { titleId } className = "h-section" > { title } </ div >
630+ < h3 id = { titleId } className = "h-section" > { title } </ h3 >
631631 { children }
632632 </ section >
633633 ) ;
@@ -637,9 +637,12 @@ function UsageWorkspaceSection({
637637 * Workspace layout for the Usage tab: a left rail lists the report sections
638638 * (Overview, Models, Providers, Coverage) and the main pane renders the selected
639639 * one. Section bodies reuse the same panel components as the classic stacked view.
640+ * The shell mounts immediately (including while loading/empty) so workspace mode
641+ * never flashes the classic EmptyState first.
640642 */
641643function UsageWorkspaceBody ( {
642644 data,
645+ loading,
643646 heatmap,
644647 weekBars,
645648 activeDays,
@@ -653,7 +656,8 @@ function UsageWorkspaceBody({
653656 locale,
654657 t,
655658} : {
656- data : UsageResponse ;
659+ data : UsageResponse | null ;
660+ loading : boolean ;
657661 heatmap : ReturnType < typeof buildHeatmap > ;
658662 weekBars : UsageDay [ ] ;
659663 activeDays : number ;
@@ -667,43 +671,53 @@ function UsageWorkspaceBody({
667671 locale : Locale ;
668672 t : TFn ;
669673} ) {
674+ const empty = ! ! data && data . summary . requests === 0 ;
670675 const sections = [
671676 {
672677 id : "overview" ,
673678 label : t ( "usage.section.overview" ) ,
674- meta : `${ data . summary . requests } ` ,
675- body : (
679+ meta : data ? `${ data . summary . requests } ` : "—" ,
680+ body : data ? (
676681 < >
677682 < UsageSummaryCards summary = { data . summary } activeDays = { activeDays } locale = { locale } t = { t } />
678683 < UsageHeatmapPanel range = { range } heatmap = { heatmap } weekBars = { weekBars } locale = { locale } t = { t } />
679684 </ >
680- ) ,
685+ ) : null ,
681686 } ,
682687 {
683688 id : "models" ,
684689 label : t ( "usage.section.models" ) ,
685- meta : `${ data . models . length } ` ,
686- body : < UsageModelsTable models = { filteredModels } modelQuery = { modelQuery } onModelQuery = { onModelQuery } locale = { locale } t = { t } workspace /> ,
690+ meta : data ? `${ data . models . length } ` : "—" ,
691+ body : data
692+ ? < UsageModelsTable models = { filteredModels } modelQuery = { modelQuery } onModelQuery = { onModelQuery } locale = { locale } t = { t } workspace />
693+ : null ,
687694 } ,
688695 {
689696 id : "providers" ,
690697 label : t ( "usage.section.providers" ) ,
691- meta : `${ data . providers . length } ` ,
692- body : < UsageProvidersTable providers = { sortedProviders } locale = { locale } t = { t } workspace /> ,
698+ meta : data ? `${ data . providers . length } ` : "—" ,
699+ body : data
700+ ? < UsageProvidersTable providers = { sortedProviders } locale = { locale } t = { t } workspace />
701+ : null ,
693702 } ,
694703 {
695704 id : "coverage" ,
696705 label : t ( "usage.section.coverage" ) ,
697- meta : formatPct ( data . summary . coverageRatio ) ,
698- body : < UsageCoveragePanel summary = { data . summary } t = { t } workspace /> ,
706+ meta : data ? formatPct ( data . summary . coverageRatio ) : "—" ,
707+ body : data ? < UsageCoveragePanel summary = { data . summary } t = { t } workspace /> : null ,
699708 } ,
700709 ] ;
701710 const selected = sections . find ( s => s . id === selectedSection ) ?? sections [ 0 ] ;
711+ const mainBody = loading && ! data
712+ ? < EmptyState title = { t ( "usage.loading" ) } />
713+ : empty
714+ ? < EmptyState title = { t ( "usage.empty" ) } />
715+ : selected . body ;
702716
703717 return (
704718 < div className = "usage-workspace-shell" >
705719 < div className = "usage-workspace-root" >
706- < aside className = "usage-workspace-rail" aria-label = { t ( "usage.title " ) } >
720+ < aside className = "usage-workspace-rail" aria-label = { t ( "usage.workspace.sections " ) } >
707721 < div className = "usage-workspace-rail-header" >
708722 < span className = "usage-workspace-rail-title" > { t ( "usage.title" ) } </ span >
709723 </ div >
@@ -722,8 +736,8 @@ function UsageWorkspaceBody({
722736 ) ) }
723737 </ div >
724738 </ aside >
725- < section className = "usage-workspace-main" aria-label = { t ( "usage.title " ) } >
726- < div className = "usw-body" > { selected . body } </ div >
739+ < section className = "usage-workspace-main" aria-label = { t ( "usage.workspace.report " ) } >
740+ < div className = "usw-body" > { mainBody } </ div >
727741 </ section >
728742 </ div >
729743 </ div >
@@ -811,13 +825,10 @@ export default function Usage({ apiBase, viewMode }: { apiBase: string; viewMode
811825 { t ( "common.retry" ) }
812826 </ button >
813827 </ Notice >
814- ) : loading && ! data ? (
815- < EmptyState title = { t ( "usage.loading" ) } />
816- ) : data ?. summary . requests === 0 ? (
817- < EmptyState title = { t ( "usage.empty" ) } />
818- ) : data && workspaceView ? (
828+ ) : workspaceView ? (
819829 < UsageWorkspaceBody
820830 data = { data }
831+ loading = { loading }
821832 heatmap = { heatmap }
822833 weekBars = { weekBars }
823834 activeDays = { activeDays }
@@ -831,6 +842,10 @@ export default function Usage({ apiBase, viewMode }: { apiBase: string; viewMode
831842 locale = { locale }
832843 t = { t }
833844 />
845+ ) : loading && ! data ? (
846+ < EmptyState title = { t ( "usage.loading" ) } />
847+ ) : data ?. summary . requests === 0 ? (
848+ < EmptyState title = { t ( "usage.empty" ) } />
834849 ) : data ? (
835850 < >
836851 < UsageSummaryCards summary = { data . summary } activeDays = { activeDays } locale = { locale } t = { t } />
0 commit comments