-
Notifications
You must be signed in to change notification settings - Fork 15
feat: redesign Memory section #2618
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7477f0e
feat: redesign Storage section
astandrik 08b44f0
fix: refactor
astandrik 3e348bb
fix: better code
astandrik 5322248
fix: better code
astandrik 9e260df
fix: dead code
astandrik 69833fa
fix: some logics fixes
astandrik 4c32c58
fix: review fixes
astandrik fec2e5d
fix: review
astandrik 867a6cc
fix: nanofix
astandrik 32df3a9
feat: redesign Memory section
astandrik b137f79
fix: remove hover
astandrik 16b0195
fix: better code
astandrik f92f597
fix: refactor
astandrik f06d479
fix: review fixes
astandrik 79faead
fix: memoize
astandrik 26e1c94
fix: review fixes
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
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,4 @@ | ||
{ | ||
"value_of_capacity": "{{value}} of {{capacity}}", | ||
"no-data": "No data" | ||
} |
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,7 @@ | ||
import {registerKeysets} from '../../../utils/i18n'; | ||
|
||
import en from './en.json'; | ||
|
||
const COMPONENT = 'ydb-progress-viewer'; | ||
|
||
export default registerKeysets(COMPONENT, {en}); |
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, | ||
withValue = false, | ||
className, | ||
width, | ||
}: ProgressContainerProps) { | ||
const progressStyle = getProgressStyle(width); | ||
|
||
return ( | ||
<Flex alignItems="center" gap="2" className={className}> | ||
<div style={progressStyle}>{children}</div> | ||
{withValue && 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, | ||
withValue = 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} | ||
withValue={withValue} | ||
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, | ||
withValue = 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} | ||
withValue={withValue} | ||
className={className} | ||
width={width} | ||
> | ||
<Progress value={MAX_PERCENTAGE} stack={stackElements} 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,4 @@ | ||
{ | ||
"alert_no-data": "no data", | ||
"context_capacity-usage": "{{value}} of {{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,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'; |
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.