-
Notifications
You must be signed in to change notification settings - Fork 17
feat: redesign Memory section #2627
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
081fa1b
feat: redesign Memory section
astandrik 6fe384a
fix: remove unused code
astandrik adc0850
fix: better code
astandrik 6b6a680
fix: better code
astandrik b0795fd
fix: nanofix
astandrik f457e90
fix: review fixes
astandrik eb542d5
fix: selfreview
astandrik 94e1cc5
fix: selfreview
astandrik d0a83e2
fix: review fixes
astandrik cddbcc6
fix: fallback
astandrik 31fcee6
fix: remove unused classes
astandrik c00fe9f
fix: memory fixes
astandrik 12f80b0
fix: chartkit tooltip fix
astandrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} />; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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]); | ||
|
|
||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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> | ||
| ); | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import type {FormatProgressViewerValues} from '../../utils/progress'; | ||
| import {isNumeric, safeParseNumber} from '../../utils/utils'; | ||
|
|
||
| import i18n from './i18n'; | ||
|
|
||
| // Constants that were previously in TenantStorage/constants | ||
| export const DEFAULT_PROGRESS_WIDTH = 400; | ||
| export const MAX_PERCENTAGE = 100; | ||
| export const MIN_PERCENTAGE = 0; | ||
| export const PROGRESS_SIZE = 's'; | ||
|
|
||
| export const isValidValue = (val?: number | string): boolean => | ||
| isNumeric(val) && safeParseNumber(val) >= 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value may be negative |
||
|
|
||
| export function calculateProgressWidth(value: number, capacity: number): number { | ||
| const rawPercentage = | ||
| capacity > 0 ? Math.floor((value / capacity) * MAX_PERCENTAGE) : MAX_PERCENTAGE; | ||
| const fillWidth = Math.max(MIN_PERCENTAGE, rawPercentage); | ||
| return Math.min(fillWidth, MAX_PERCENTAGE); | ||
| } | ||
|
|
||
| export function getProgressStyle(width?: number | 'full') { | ||
| const isFullWidth = width === 'full'; | ||
| const validatedWidth = isFullWidth ? 0 : Math.max(0, width || DEFAULT_PROGRESS_WIDTH); | ||
|
|
||
| return { | ||
| width: isFullWidth ? '100%' : `${validatedWidth}px`, | ||
| flex: isFullWidth ? '1' : 'none', | ||
| }; | ||
| } | ||
|
|
||
| export function formatProgressText( | ||
| valueText: string | number | undefined, | ||
| capacityText: string | number | undefined, | ||
| numericCapacity: number, | ||
| ): string { | ||
| if (numericCapacity <= 0) { | ||
| return String(valueText); | ||
| } | ||
| return i18n('context_capacity-usage', {value: valueText, capacity: capacityText}); | ||
| } | ||
|
|
||
| export function formatDisplayValues( | ||
| value: number | string | undefined, | ||
| capacity: number | string | undefined, | ||
| formatValues?: FormatProgressViewerValues, | ||
| ): [string | number | undefined, string | number | undefined] { | ||
| if (formatValues) { | ||
| const result = formatValues(Number(value), Number(capacity)); | ||
| return [result[0], result[1]] as [string | number | undefined, string | number | undefined]; | ||
| } | ||
| return [value, capacity]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type {ProgressSize} from '@gravity-ui/uikit'; | ||
|
|
||
| import type {FormatProgressViewerValues} from '../../utils/progress'; | ||
| import type {MemorySegment} from '../MemoryViewer/utils'; | ||
|
|
||
| export interface ProgressWrapperBaseProps { | ||
| formatValues?: FormatProgressViewerValues; | ||
| className?: string; | ||
| width?: number | 'full'; | ||
| size?: ProgressSize; | ||
| withCapacityUsage?: boolean; | ||
| } | ||
|
|
||
| export interface ProgressWrapperSingleProps extends ProgressWrapperBaseProps { | ||
| value?: number | string; | ||
| capacity?: number | string; | ||
| stack?: never; | ||
| } | ||
|
|
||
| export interface ProgressWrapperStackProps extends ProgressWrapperBaseProps { | ||
| stack: MemorySegment[]; | ||
| totalCapacity?: number | string; | ||
| value?: never; | ||
| capacity?: never; | ||
| } | ||
|
|
||
| export type ProgressWrapperProps = ProgressWrapperSingleProps | ProgressWrapperStackProps; | ||
|
|
||
| export interface ProgressContainerProps { | ||
| children: React.ReactNode; | ||
| displayText?: string; | ||
| withCapacityUsage?: boolean; | ||
| className?: string; | ||
| width?: number | 'full'; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.