Skip to content

feat: redesign Storage section #2608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/components/InfoViewer/InfoViewer.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@use '../../styles/mixins.scss';

.info-viewer {
--ydb-info-viewer-font-size: var(--g-text-body-2-font-size);
--ydb-info-viewer-line-height: var(--g-text-body-2-line-height);
Expand Down Expand Up @@ -28,6 +30,10 @@

max-width: 100%;
padding-top: 4px;

&:first-child {
padding-top: 0;
}
}

&__label {
Expand Down Expand Up @@ -88,4 +94,18 @@
}
}
}

&_variant_small {
.info-viewer__title {
margin: 0 0 var(--g-spacing-3);

color: var(--g-color-text-primary);
@include mixins.subheader-1-typography();
}

.info-viewer__label {
color: var(--g-color-text-secondary);
@include mixins.body-1-typography();
}
}
}
4 changes: 3 additions & 1 deletion src/components/InfoViewer/InfoViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface InfoViewerProps {
info?: InfoViewerItem[];
dots?: boolean;
size?: 's';
variant?: 'default' | 'small';
className?: string;
multilineLabels?: boolean;
renderEmptyState?: (props?: Pick<InfoViewerProps, 'title' | 'size'>) => React.ReactNode;
Expand All @@ -28,6 +29,7 @@ export const InfoViewer = ({
info,
dots = true,
size,
variant = 'default',
className,
multilineLabels,
renderEmptyState,
Expand All @@ -37,7 +39,7 @@ export const InfoViewer = ({
}

return (
<div className={b({size}, className)}>
<div className={b({size, variant}, className)}>
{title && <div className={b('title')}>{title}</div>}
{info && info.length > 0 ? (
<div className={b('items')}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MemoryViewer/MemoryViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type {TMemoryStats} from '../../types/api/nodes';
import {formatBytes} from '../../utils/bytesParsers';
import {cn} from '../../utils/cn';
import {GIGABYTE} from '../../utils/constants';
import type {FormatProgressViewerValues} from '../../utils/progress';
import {calculateProgressStatus} from '../../utils/progress';
import {isNumeric} from '../../utils/utils';
import {HoverPopup} from '../HoverPopup/HoverPopup';
import type {FormatProgressViewerValues} from '../ProgressViewer/ProgressViewer';
import {ProgressViewer} from '../ProgressViewer/ProgressViewer';

import {calculateAllocatedMemory, getMemorySegments} from './utils';
Expand Down
19 changes: 3 additions & 16 deletions src/components/ProgressViewer/ProgressViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {useTheme} from '@gravity-ui/uikit';

import {cn} from '../../utils/cn';
import {formatNumber, roundToPrecision} from '../../utils/dataFormatters/dataFormatters';
import {calculateProgressStatus} from '../../utils/progress';
import {calculateProgressStatus, defaultFormatProgressValues} from '../../utils/progress';
import type {FormatProgressViewerValues} from '../../utils/progress';
import {isNumeric} from '../../utils/utils';

import './ProgressViewer.scss';
Expand All @@ -11,19 +11,6 @@ const b = cn('progress-viewer');

type ProgressViewerSize = 'xs' | 's' | 'ns' | 'm' | 'n' | 'l' | 'head';

export type FormatProgressViewerValues = (
value?: number,
capacity?: number,
) => (string | number | undefined)[];

const formatValue = (value?: number) => {
return formatNumber(roundToPrecision(Number(value), 2));
};

const defaultFormatValues: FormatProgressViewerValues = (value, total) => {
return [formatValue(value), formatValue(total)];
};

/*

Props description:
Expand Down Expand Up @@ -56,7 +43,7 @@ export interface ProgressViewerProps {
export function ProgressViewer({
value,
capacity,
formatValues = defaultFormatValues,
formatValues = defaultFormatProgressValues,
percents,
withOverflow,
className,
Expand Down
3 changes: 3 additions & 0 deletions src/components/ProgressViewer/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"no-data": "No data"
}
7 changes: 7 additions & 0 deletions src/components/ProgressViewer/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {registerKeysets} from '../../../utils/i18n';

import en from './en.json';

const COMPONENT = 'ydb-progress-viewer';

export default registerKeysets(COMPONENT, {en});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {StringParam, useQueryParams} from 'use-query-params';

import {
TENANT_CPU_NODES_MODE_IDS,
TENANT_CPU_TABS_IDS,
} from '../../../../../store/reducers/tenant/constants';
tenantCpuTabSchema,
tenantNodesModeSchema,
} from '../../../../../store/reducers/tenant/types';
import type {TenantCpuTab, TenantNodesMode} from '../../../../../store/reducers/tenant/types';

export function useTenantCpuQueryParams() {
Expand All @@ -12,27 +12,8 @@ export function useTenantCpuQueryParams() {
nodesMode: StringParam,
});

// Parse and validate cpuTab with fallback to nodes
const cpuTab: TenantCpuTab = (() => {
if (!queryParams.cpuTab) {
return TENANT_CPU_TABS_IDS.nodes;
}
const validTabs = Object.values(TENANT_CPU_TABS_IDS) as string[];
return validTabs.includes(queryParams.cpuTab)
? (queryParams.cpuTab as TenantCpuTab)
: TENANT_CPU_TABS_IDS.nodes;
})();

// Parse and validate nodesMode with fallback to load
const nodesMode: TenantNodesMode = (() => {
if (!queryParams.nodesMode) {
return TENANT_CPU_NODES_MODE_IDS.load;
}
const validModes = Object.values(TENANT_CPU_NODES_MODE_IDS) as string[];
return validModes.includes(queryParams.nodesMode)
? (queryParams.nodesMode as TenantNodesMode)
: TENANT_CPU_NODES_MODE_IDS.load;
})();
const cpuTab: TenantCpuTab = tenantCpuTabSchema.parse(queryParams.cpuTab);
const nodesMode: TenantNodesMode = tenantNodesModeSchema.parse(queryParams.nodesMode);

const handleCpuTabChange = (value: TenantCpuTab) => {
setQueryParams({cpuTab: value}, 'replaceIn');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.ydb-tenant-dashboard {
width: var(--diagnostics-section-table-width);
margin-bottom: var(--diagnostics-section-margin);
margin-bottom: var(--g-spacing-4);

&__charts {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';

import {Flex, Progress, Text} from '@gravity-ui/uikit';

import {defaultFormatProgressValues} from '../../../../../utils/progress';
import type {FormatProgressViewerValues} from '../../../../../utils/progress';
import {isNumeric, safeParseNumber} from '../../../../../utils/utils';

import {DEFAULT_PROGRESS_WIDTH, MAX_PERCENTAGE, MIN_PERCENTAGE, PROGRESS_SIZE} from './constants';
import i18n from './i18n';

interface ProgressWrapperProps {
value?: number | string;
capacity?: number | string;
formatValues?: FormatProgressViewerValues;
className?: string;
width?: number;
}

const isValidValue = (val?: number | string): boolean =>
isNumeric(val) && safeParseNumber(val) >= 0;

export function ProgressWrapper({
value,
capacity,
formatValues = defaultFormatProgressValues,
className,
width = DEFAULT_PROGRESS_WIDTH,
}: ProgressWrapperProps) {
if (!isValidValue(value)) {
return <div className={className}>{i18n('alert_no-data')}</div>;
}

const numericValue = safeParseNumber(value);
const numericCapacity = safeParseNumber(capacity);

const rawPercentage =
numericCapacity > 0
? Math.floor((numericValue / numericCapacity) * MAX_PERCENTAGE)
: MAX_PERCENTAGE;
const fillWidth = Math.max(MIN_PERCENTAGE, rawPercentage);
const clampedFillWidth = Math.min(fillWidth, MAX_PERCENTAGE);

const [valueText, capacityText] = React.useMemo(() => {
return formatValues(Number(value), Number(capacity));
}, [formatValues, value, capacity]);

const displayText = React.useMemo(() => {
if (numericCapacity <= 0) {
return String(valueText);
}
return i18n('context_capacity-usage', {value: valueText, capacity: capacityText});
}, [valueText, capacityText, numericCapacity]);

const validatedWidth = Math.max(0, width);

return (
<Flex alignItems="center" gap="2" className={className}>
<div style={{width: `${validatedWidth}px`}}>
<Progress value={clampedFillWidth} theme="success" size={PROGRESS_SIZE} />
</div>
<Text variant="body-1" color="secondary">
{displayText}
</Text>
</Flex>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.tenant-storage {
&__tabs-container {
margin-top: var(--g-spacing-3);
}

&__tab-content {
margin-top: var(--g-spacing-3);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import React from 'react';

import {Tab, TabList, TabProvider} from '@gravity-ui/uikit';

import {InfoViewer} from '../../../../../components/InfoViewer/InfoViewer';
import {LabelWithPopover} from '../../../../../components/LabelWithPopover';
import {ProgressViewer} from '../../../../../components/ProgressViewer/ProgressViewer';
import {TENANT_STORAGE_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
import {cn} from '../../../../../utils/cn';
import {formatStorageValues} from '../../../../../utils/dataFormatters/dataFormatters';
import {TenantDashboard} from '../TenantDashboard/TenantDashboard';
import i18n from '../i18n';
import {b} from '../utils';

import {ProgressWrapper} from './ProgressWrapper';
import {TopGroups} from './TopGroups';
import {TopTables} from './TopTables';
import {storageDashboardConfig} from './storageDashboardConfig';
import {useTenantStorageQueryParams} from './useTenantStorageQueryParams';

import './TenantStorage.scss';

import '../TenantOverview.scss';
const tenantStorageCn = cn('tenant-storage');

const storageTabs = [
{id: TENANT_STORAGE_TABS_IDS.tables, title: i18n('title_top-tables-by-size')},
{id: TENANT_STORAGE_TABS_IDS.groups, title: i18n('title_top-groups-by-usage')},
];

export interface TenantStorageMetrics {
blobStorageUsed?: number;
Expand All @@ -27,8 +38,21 @@ interface TenantStorageProps {
}

export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
const {storageTab, handleStorageTabChange} = useTenantStorageQueryParams();

const {blobStorageUsed, tabletStorageUsed, blobStorageLimit, tabletStorageLimit} = metrics;

const renderTabContent = () => {
switch (storageTab) {
case TENANT_STORAGE_TABS_IDS.tables:
return <TopTables database={tenantName} />;
case TENANT_STORAGE_TABS_IDS.groups:
return <TopGroups tenant={tenantName} />;
default:
return null;
}
};

const info = [
{
label: (
Expand All @@ -38,11 +62,10 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
/>
),
value: (
<ProgressViewer
<ProgressWrapper
value={tabletStorageUsed}
capacity={tabletStorageLimit}
formatValues={formatStorageValues}
colorizeProgress={true}
/>
),
},
Expand All @@ -54,11 +77,10 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
/>
),
value: (
<ProgressViewer
<ProgressWrapper
value={blobStorageUsed}
capacity={blobStorageLimit}
formatValues={formatStorageValues}
colorizeProgress={true}
/>
),
},
Expand All @@ -67,9 +89,23 @@ export function TenantStorage({tenantName, metrics}: TenantStorageProps) {
return (
<React.Fragment>
<TenantDashboard database={tenantName} charts={storageDashboardConfig} />
<InfoViewer className={b('storage-info')} title="Storage details" info={info} />
<TopTables database={tenantName} />
<TopGroups tenant={tenantName} />
<InfoViewer variant="small" title={i18n('title_storage-details')} info={info} />

<div className={tenantStorageCn('tabs-container')}>
<TabProvider value={storageTab}>
<TabList size="m">
{storageTabs.map(({id, title}) => {
return (
<Tab key={id} value={id} onClick={() => handleStorageTabChange(id)}>
{title}
</Tab>
);
})}
</TabList>
</TabProvider>

<div className={tenantStorageCn('tab-content')}>{renderTabContent()}</div>
</div>
</React.Fragment>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {TENANT_OVERVIEW_TABLES_SETTINGS} from '../../../../../utils/constants';
import {useAutoRefreshInterval} from '../../../../../utils/hooks';
import {parseQueryErrorToString} from '../../../../../utils/query';
import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout';
import {getSectionTitle} from '../getSectionTitle';
import i18n from '../i18n';

import '../TenantOverview.scss';

Expand Down Expand Up @@ -57,14 +55,8 @@ export function TopTables({database}: TopTablesProps) {
) : null,
},
];
const title = getSectionTitle({
entity: i18n('tables'),
postfix: i18n('by-size'),
});

return (
<TenantOverviewTableLayout
title={title}
loading={loading}
error={parseQueryErrorToString(error)}
withData={Boolean(currentData)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const DEFAULT_PROGRESS_WIDTH = 400;
export const MAX_PERCENTAGE = 100;
export const MIN_PERCENTAGE = 0;

export const PROGRESS_SIZE = 's';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"alert_no-data": "No data",
"context_capacity-usage": "{{value}} of {{capacity}}"
}
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is and src/components/ProgressViewer/i18n/en.json are duplicates

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest?

Copy link
Collaborator Author

@astandrik astandrik Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

cluster also has this key

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key in ProgressView is unused - removed it

Loading
Loading