-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Changes from all commits
7477f0e
08b44f0
3e348bb
5322248
9e260df
69833fa
4c32c58
fec2e5d
867a6cc
6cb6e80
bfafef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"no-data": "No data" | ||
} |
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 |
---|---|---|
@@ -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} /> | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</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 |
---|---|---|
@@ -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
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. It is and src/components/ProgressViewer/i18n/en.json are duplicates 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. What do you suggest? 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. key in ProgressView is unused - removed it |
Uh oh!
There was an error while loading. Please reload this page.