11import React from 'react' ;
22
3+ import { Tab , TabList , TabProvider } from '@gravity-ui/uikit' ;
4+ import { useLocation } from 'react-router-dom' ;
5+
36import { InfoViewer } from '../../../../../components/InfoViewer/InfoViewer' ;
7+ import { InternalLink } from '../../../../../components/InternalLink' ;
48import { LabelWithPopover } from '../../../../../components/LabelWithPopover' ;
59import { ProgressViewer } from '../../../../../components/ProgressViewer/ProgressViewer' ;
10+ import { parseQuery } from '../../../../../routes' ;
11+ import { TENANT_STORAGE_TABS_IDS } from '../../../../../store/reducers/tenant/constants' ;
12+ import { setStorageTab } from '../../../../../store/reducers/tenant/tenant' ;
13+ import { cn } from '../../../../../utils/cn' ;
614import { formatStorageValues } from '../../../../../utils/dataFormatters/dataFormatters' ;
15+ import { useTypedDispatch , useTypedSelector } from '../../../../../utils/hooks' ;
16+ import { TenantTabsGroups , getTenantPath } from '../../../TenantPages' ;
717import { TenantDashboard } from '../TenantDashboard/TenantDashboard' ;
818import i18n from '../i18n' ;
9- import { b } from '../utils' ;
1019
1120import { TopGroups } from './TopGroups' ;
1221import { TopTables } from './TopTables' ;
1322import { storageDashboardConfig } from './storageDashboardConfig' ;
1423
15- import '../TenantOverview.scss' ;
24+ import './TenantStorage.scss' ;
25+
26+ const tenantStorageCn = cn ( 'tenant-storage' ) ;
27+
28+ const storageTabs = [
29+ { id : TENANT_STORAGE_TABS_IDS . tables , title : i18n ( 'title_top-tables-by-size' ) } ,
30+ { id : TENANT_STORAGE_TABS_IDS . groups , title : i18n ( 'title_top-groups-by-usage' ) } ,
31+ ] ;
1632
1733export interface TenantStorageMetrics {
1834 blobStorageUsed ?: number ;
@@ -27,8 +43,31 @@ interface TenantStorageProps {
2743}
2844
2945export function TenantStorage ( { tenantName, metrics} : TenantStorageProps ) {
46+ const dispatch = useTypedDispatch ( ) ;
47+ const location = useLocation ( ) ;
48+ const { storageTab = TENANT_STORAGE_TABS_IDS . tables } = useTypedSelector ( ( state ) => state . tenant ) ;
49+
3050 const { blobStorageUsed, tabletStorageUsed, blobStorageLimit, tabletStorageLimit} = metrics ;
3151
52+ const queryParams = parseQuery ( location ) ;
53+
54+ React . useEffect ( ( ) => {
55+ if ( ! storageTab ) {
56+ dispatch ( setStorageTab ( TENANT_STORAGE_TABS_IDS . tables ) ) ;
57+ }
58+ } , [ storageTab , dispatch ] ) ;
59+
60+ const renderTabContent = ( ) => {
61+ switch ( storageTab ) {
62+ case TENANT_STORAGE_TABS_IDS . tables :
63+ return < TopTables database = { tenantName } /> ;
64+ case TENANT_STORAGE_TABS_IDS . groups :
65+ return < TopGroups tenant = { tenantName } /> ;
66+ default :
67+ return null ;
68+ }
69+ } ;
70+
3271 const info = [
3372 {
3473 label : (
@@ -43,6 +82,7 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
4382 capacity = { tabletStorageLimit }
4483 formatValues = { formatStorageValues }
4584 colorizeProgress = { true }
85+ size = "storage"
4686 />
4787 ) ,
4888 } ,
@@ -59,6 +99,7 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
5999 capacity = { blobStorageLimit }
60100 formatValues = { formatStorageValues }
61101 colorizeProgress = { true }
102+ size = "storage"
62103 />
63104 ) ,
64105 } ,
@@ -67,9 +108,33 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
67108 return (
68109 < React . Fragment >
69110 < TenantDashboard database = { tenantName } charts = { storageDashboardConfig } />
70- < InfoViewer className = { b ( 'storage-info' ) } title = "Storage details" info = { info } />
71- < TopTables database = { tenantName } />
72- < TopGroups tenant = { tenantName } />
111+ < InfoViewer
112+ variant = "storage"
113+ title = { i18n ( 'storage.storage-details-title' ) }
114+ info = { info }
115+ />
116+
117+ < div className = { tenantStorageCn ( 'tabs-container' ) } >
118+ < TabProvider value = { storageTab } >
119+ < TabList size = "m" >
120+ { storageTabs . map ( ( { id, title} ) => {
121+ const path = getTenantPath ( {
122+ ...queryParams ,
123+ [ TenantTabsGroups . storageTab ] : id ,
124+ } ) ;
125+ return (
126+ < Tab key = { id } value = { id } >
127+ < InternalLink to = { path } as = "tab" >
128+ { title }
129+ </ InternalLink >
130+ </ Tab >
131+ ) ;
132+ } ) }
133+ </ TabList >
134+ </ TabProvider >
135+
136+ < div className = { tenantStorageCn ( 'tab-content' ) } > { renderTabContent ( ) } </ div >
137+ </ div >
73138 </ React . Fragment >
74139 ) ;
75140}
0 commit comments