Skip to content
Merged
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
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@bem-react/classname": "^1.6.0",
"@ebay/nice-modal-react": "^1.2.13",
"@gravity-ui/axios-wrapper": "^1.5.1",
"@gravity-ui/chartkit": "^7.0.1",
"@gravity-ui/chartkit": "^7.1.0",
"@gravity-ui/components": "^4.4.0",
"@gravity-ui/date-components": "^3.2.3",
"@gravity-ui/date-utils": "^2.5.6",
Expand Down
18 changes: 5 additions & 13 deletions src/components/MemoryViewer/MemoryViewer.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$memory-type-colors: (
'AllocatorCachesMemory': var(--g-color-base-utility-medium-hover),
'SharedCacheConsumption': var(--g-color-base-info-medium-hover),
'MemTableConsumption': var(--g-color-base-warning-medium-hover),
'QueryExecutionConsumption': var(--g-color-base-positive-medium-hover),
'Other': var(--g-color-base-generic-medium-hover),
'AllocatorCachesMemory': var(--g-color-base-danger-medium),
'SharedCacheConsumption': var(--g-color-base-info-medium),
'MemTableConsumption': var(--g-color-base-warning-medium),
'QueryExecutionConsumption': var(--g-color-base-positive-medium),
'Other': var(--g-color-base-neutral-medium),
);

@mixin memory-type-color($type) {
Expand Down Expand Up @@ -31,8 +31,6 @@ $memory-type-colors: (
}

&__container {
display: flex;

padding: 2px 0;
}

Expand Down Expand Up @@ -93,10 +91,4 @@ $memory-type-colors: (
}
}
}

&__text {
display: flex;
justify-content: center;
align-items: center;
}
}
10 changes: 6 additions & 4 deletions src/components/MemoryViewer/MemoryViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DefinitionList, useTheme} from '@gravity-ui/uikit';
import {DefinitionList, Flex, useTheme} from '@gravity-ui/uikit';

import type {TMemoryStats} from '../../types/api/nodes';
import {formatBytes} from '../../utils/bytesParsers';
Expand Down Expand Up @@ -107,10 +107,10 @@ export function MemoryViewer({
<DefinitionList.Item
key={label}
name={
<div className={b('container')}>
<Flex alignItems="center" gap="1" className={b('container')}>
<div className={b('legend', {type: key})}></div>
<div className={b('name')}>{label}</div>
</div>
</Flex>
}
>
{segmentCapacity ? (
Expand Down Expand Up @@ -161,7 +161,9 @@ export function MemoryViewer({
/>
);
})}
<div className={b('text')}>{renderContent()}</div>
<Flex justifyContent="center" alignItems="center" className={b('text')}>
{renderContent()}
</Flex>
</div>
</div>
</HoverPopup>
Expand Down
3 changes: 2 additions & 1 deletion src/components/MemoryViewer/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"text_usage": "Usage",
"text_soft-limit": "Soft Limit",
"text_hard-limit": "Hard Limit",
"text_other": "Other"
"text_other": "Other",
"text_memory-details": "Memory Details"
}
17 changes: 15 additions & 2 deletions src/components/MemoryViewer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@ export function calculateAllocatedMemory(stats: TMemoryStats) {
return String(allocatedMemory + allocatorCaches);
}

export function getMaybeNumber(value: string | number | undefined): number | undefined {
function getMaybeNumber(value: string | number | undefined): number | undefined {
return isNumeric(value) ? parseFloat(String(value)) : undefined;
}

interface MemorySegment {
export interface MemorySegment {
label: string;
key: string;
value: number;
capacity?: number;
isInfo?: boolean;
}

// Memory segment colors using CSS variables for theme support
export const MEMORY_SEGMENT_COLORS: Record<string, string> = {
AllocatorCachesMemory: 'var(--g-color-base-danger-medium)',
SharedCacheConsumption: 'var(--g-color-base-info-medium)',
MemTableConsumption: 'var(--g-color-base-warning-medium)',
QueryExecutionConsumption: 'var(--g-color-base-positive-medium)',
Other: 'var(--g-color-base-neutral-medium)',
};

export function getMemorySegmentColor(key: string): string {
return MEMORY_SEGMENT_COLORS[key] || MEMORY_SEGMENT_COLORS['Other'];
}

export function getMemorySegments(stats: TMemoryStats, memoryUsage: number): MemorySegment[] {
const segments = [
{
Expand Down
25 changes: 25 additions & 0 deletions src/components/ProgressWrapper/ProgressContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Flex, Text} from '@gravity-ui/uikit';

import {getProgressStyle} from './progressUtils';
import type {ProgressContainerProps} from './types';

export function ProgressContainer({
children,
displayText,
withCapacityUsage = false,
className,
width,
}: ProgressContainerProps) {
const progressStyle = getProgressStyle(width);

return (
<Flex alignItems="center" gap="2" className={className}>
<div style={progressStyle}>{children}</div>
{withCapacityUsage && displayText && (
<Text variant="body-1" color="secondary">
{displayText}
</Text>
)}
</Flex>
);
}
10 changes: 10 additions & 0 deletions src/components/ProgressWrapper/ProgressWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {SingleProgress} from './SingleProgress';
import {StackProgress} from './StackProgress';
import type {ProgressWrapperProps} from './types';

export function ProgressWrapper(props: ProgressWrapperProps) {
if ('stack' in props && props.stack) {
return <StackProgress {...props} />;
}
return <SingleProgress {...props} />;
}
54 changes: 54 additions & 0 deletions src/components/ProgressWrapper/SingleProgress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';

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

import {defaultFormatProgressValues} from '../../utils/progress';
import {safeParseNumber} from '../../utils/utils';

import {ProgressContainer} from './ProgressContainer';
import i18n from './i18n';
import {
PROGRESS_SIZE,
calculateProgressWidth,
formatDisplayValues,
formatProgressText,
isValidValue,
} from './progressUtils';
import type {ProgressWrapperSingleProps} from './types';

export function SingleProgress({
value,
capacity,
formatValues = defaultFormatProgressValues,
className,
width,
size = PROGRESS_SIZE,
withCapacityUsage = false,
}: ProgressWrapperSingleProps) {
if (!isValidValue(value)) {
return <div className={className}>{i18n('alert_no-data')}</div>;
}

const numericValue = safeParseNumber(value);
const numericCapacity = safeParseNumber(capacity);
const clampedFillWidth = calculateProgressWidth(numericValue, numericCapacity);

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

const displayText = React.useMemo(() => {
return formatProgressText(valueText, capacityText, numericCapacity);
}, [valueText, capacityText, numericCapacity]);

return (
<ProgressContainer
displayText={displayText}
withCapacityUsage={withCapacityUsage}
className={className}
width={width}
>
<Progress value={clampedFillWidth} theme="success" size={size} />
</ProgressContainer>
);
}
72 changes: 72 additions & 0 deletions src/components/ProgressWrapper/StackProgress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';

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

import {defaultFormatProgressValues} from '../../utils/progress';
import {safeParseNumber} from '../../utils/utils';
import {getMemorySegmentColor} from '../MemoryViewer/utils';

import {ProgressContainer} from './ProgressContainer';
import i18n from './i18n';
import {
MAX_PERCENTAGE,
PROGRESS_SIZE,
formatDisplayValues,
formatProgressText,
} from './progressUtils';
import type {ProgressWrapperStackProps} from './types';

export function StackProgress({
stack,
totalCapacity,
formatValues = defaultFormatProgressValues,
className,
width,
size = PROGRESS_SIZE,
withCapacityUsage = false,
}: ProgressWrapperStackProps) {
const displaySegments = React.useMemo(() => {
return stack.filter((segment) => !segment.isInfo && segment.value > 0);
}, [stack]);

if (displaySegments.length === 0) {
return <div className={className}>{i18n('alert_no-data')}</div>;
}

const totalValue = React.useMemo(() => {
return displaySegments.reduce((sum, segment) => sum + segment.value, 0);
}, [displaySegments]);

const numericTotalCapacity = React.useMemo(() => {
return safeParseNumber(totalCapacity);
}, [totalCapacity]);

const maxValue = numericTotalCapacity || totalValue;

const stackElements = React.useMemo(() => {
return displaySegments.map((segment) => ({
value: maxValue > 0 ? (segment.value / maxValue) * MAX_PERCENTAGE : 0,
color: getMemorySegmentColor(segment.key),
title: segment.label,
}));
}, [displaySegments, maxValue]);

const [totalValueText, totalCapacityText] = React.useMemo(() => {
return formatDisplayValues(totalValue, numericTotalCapacity || totalValue, formatValues);
}, [formatValues, totalValue, numericTotalCapacity]);

const displayText = React.useMemo(() => {
return formatProgressText(totalValueText, totalCapacityText, numericTotalCapacity || 0);
}, [totalValueText, totalCapacityText, numericTotalCapacity]);

return (
<ProgressContainer
displayText={displayText}
withCapacityUsage={withCapacityUsage}
className={className}
width={width}
>
<Progress value={MAX_PERCENTAGE} stack={stackElements} size={size} />
</ProgressContainer>
);
}
11 changes: 11 additions & 0 deletions src/components/ProgressWrapper/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {registerKeysets} from '../../../utils/i18n';

import en from './en.json';

const COMPONENT = 'progress-wrapper';

const keysets = {
en,
};

export default registerKeysets(COMPONENT, keysets);
18 changes: 18 additions & 0 deletions src/components/ProgressWrapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Main component - public API
export {ProgressWrapper} from './ProgressWrapper';

// Individual components - for direct usage if needed
export {SingleProgress} from './SingleProgress';
export {StackProgress} from './StackProgress';
export {ProgressContainer} from './ProgressContainer';

// Types - for consumers
export type {
ProgressWrapperProps,
ProgressWrapperSingleProps,
ProgressWrapperStackProps,
ProgressContainerProps,
} from './types';

// Utils - for advanced usage
export * from './progressUtils';
Loading
Loading